插入具有特定 contactid 的 RawContact
我正在尝试在 android 中创建一个具有特定联系人 id 的 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) {
...
}
我做错了什么?
I am trying to create a rawcontact in android that has a specific contact id, so it is linked to other rawcontacts with the same contactid (not rawcontactid).
The problem is I am unable to insert the Contact_ID into the ContentProviderOpertations.
Using the following code return "Insert failed"
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) {
...
}
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可以这样做,但不是按照您想要的方式。您可以通过将类型设置为 TYPE_KEEP_TOGETHER 将两个原始联系人 ID 添加到 AggregationExceptions 表中,使联系人应用程序加入两个原始联系人
It is possible to do this but not in the way you want. You can make Contacts application join two raw contacts by adding both raw contact ids to AggregationExceptions table by setting the type as TYPE_KEEP_TOGETHER
http://developer.android.com/reference/android/provider/ContactsContract.AggregationExceptions.html
你不能这样做。 Android 联系人聚合器自动将原始联系人聚合为联系人。您无需担心将原始联系人分配给联系人。
You cannot do this. The Android contact aggregator aggregates raw contacts into contacts automatically. You should not need to worry about assigning a raw contact to a contact.