Q: Creation of contacts

Put your problem here if it does not fit any of the other categories.

Q: Creation of contacts

Postby paradroid666 » Wed Oct 20, 2010 1:50 pm


using the API I am trying to create a contact, using the API 2.x and not the old one. Here http://developer.android.com/guide/topi ... iders.html it only explains the old API. I haven't found any proper tutorial, example, etc. showing how to create a contact. As far as I have figured out I have to create a raw contact, under raw contacts I found http://developer.android.com/reference/ ... tacts.html (sorry for the ugly link I am only allowed to post one link...) from there I tried

Code: Select all
ContentValues values = new ContentValues();
values.put(RawContacts.ACCOUNT_TYPE, accountType); //accountType = "xxxx"
values.put(RawContacts.ACCOUNT_NAME, accountName); //accountName = "aaaa"
Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
long rawContactId = ContentUris.parseId(rawContactUri);
values.put(Data.RAW_CONTACT_ID, rawContactId);
values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
values.put(StructuredName.DISPLAY_NAME, "Mike Sullivan");
getContentResolver().insert(Data.CONTENT_URI, values);

The last line of code shows that "Data.CONTENT_URI" cannot be resolved. It looks a little bit that this line of code is for the 1.6 API, I have changed the Data.CONTENT_URI to ContactsContract.Data.CONTENT_URI. At least the code compiles and executes, but I still don't have a contact Mike Sullivan in my addressbook afterwards. I exchanged now as well the other "Data" with "ContactsContract.Data" still no changes.

Has anyone an easy example how to create a person in the addressbook on 2.x?

Junior Developer
Junior Developer
Posts: 20
Joined: Fri May 21, 2010 2:36 pm


Re: Q: Creation of contacts

Postby Unicate » Fri Mar 04, 2011 10:54 am

I have the same problem. Is there a solution?
Junior Developer
Junior Developer
Posts: 10
Joined: Thu Sep 02, 2010 8:23 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests