问题
After searching almost the whole Internet already I have a really big headache from this problem. I have a code that works on any APIs, in addition to API 19 KitKat (Google Nexus). It is a typical code for adding/inserting contacts to device. Anyone have any ideas why this does not work right?
ArrayList<ContentProviderOperation> op_list = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = ContentProviderOperation
.newInsert(RawContacts.CONTENT_URI);
builder.withValue(RawContacts.ACCOUNT_NAME,
appData.getAccount().name);
builder.withValue(RawContacts.ACCOUNT_TYPE,
appData.getAccount().type);
builder.withValue(RawContacts.SYNC1, user.getName());
op_list.add(builder.build());
builder = ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI);
builder.withValueBackReference(
ContactsContract.CommonDataKinds.StructuredName.RAW_CONTACT_ID,
0);
builder.withValue(
ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
builder.withValue(
ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
user.getName());
op_list.add(builder.build());
builder = ContentProviderOperation
.newInsert(ContactsContract.Data.CONTENT_URI);
builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
builder.withValue(ContactsContract.Data.MIMETYPE,
"vnd.android.cursor.item/customMimeType");
builder.withValue(ContactsContract.Data.DATA1, user.getID());
builder.withValue(ContactsContract.Data.DATA2, "Profile");
builder.withValue(ContactsContract.Data.DATA3, "Send message");
builder.withValue(Data.DATA10, user.getID());
op_list.add(builder.build());
try {
contentResolver.applyBatch(ContactsContract.AUTHORITY, op_list);
} catch (Exception e) {
e.printStackTrace();
}
No exceptions are thrown, but the contact cannot be found in contact list after insert.
回答1:
Try not to use DATA3 column (it has LABEL alias for android framework MIME types). And I would change MIMETYPE to something completely different from framework MIME types, like org.myprog.app/mycustomType
来源:https://stackoverflow.com/questions/24814814/kitkat-api-19-inserting-contact