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/topics/providers/content-providers.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/android/provider/ContactsContract.RawContacts.html from there I tried
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.clear();
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?
Edit: I made some progress, it looks like that I always need an account on my phone to add a contact. My phone has account type com.google and account name xxxxx@gmail.com. The emulator has nothing. I wonder to which account I have to add my contacts? Can I assume that I ALWAYS have exactly one gmail account and take this one?