I am trying to create a user profile in ContactsContract...because there is not one, and I need one for testing. I don't have a real-life Android device, and only have the AVD Emulator for testing.
Here is the code block that I am working from:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null)
.build());
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, Profile.CONTENT_RAW_CONTACTS_URI)
.withValue(Profile.IS_USER_PROFILE, 1)
.build());
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, name)
.build());
this.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
If you remove the lines for making this entry a user profile, it works fine (i.e., will insert the name). However, I can not figure out how to set the entry with the IS_USER_PROFILE flag.
Can you create a user profile from an App? If so, any ideas on why this won't work?
Many thanks! Scott