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(StructuredName.DISPLAY_NAME, "Mike Sullivan");
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?