android-插入RawContact与特定的contactid
作者:互联网
我正在尝试在具有特定联系人ID的android中创建rawcontact,因此将其链接到具有相同contactid(而不是rawcontactid)的其他rawcontact.
问题是我无法将Contact_ID插入ContentProviderOpertations.
使用以下代码返回“插入失败”
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int id = (int) contactId;
String condition = Data.RAW_CONTACT_ID + "=?";
String[] parameters = { "" + id };
try {
String accountName = account.name;
String accountType = account.type;
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, accountType)
.withValue(RawContacts.ACCOUNT_NAME, accountName).build());
ops.add(getAccountGroupOperation(account));
ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID, 0)
.withValue(Data.CONTACT_ID, "" + id)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, contact.getName())
.build());
MyApplication.getAppContext().getContentResolver()
.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
...
}
我究竟做错了什么?
解决方法:
可以执行此操作,但操作方式不理想.您可以通过将两个原始联系人ID都添加到AggregationExceptions表(通过将类型设置为TYPE_KEEP_TOGETHER)来使Contacts应用程序加入两个原始联系人
http://developer.android.com/reference/android/provider/ContactsContract.AggregationExceptions.html
标签:contacts,android-contacts,contactscontract,rawcontacts,android 来源: https://codeday.me/bug/20191201/2084346.html