添加的联系人不会显示在android中的联系人中

时间:2011-07-26 14:36:58

标签: android

    ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();

    ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
    builder.withValue(RawContacts.ACCOUNT_NAME, account.name);
    builder.withValue(RawContacts.ACCOUNT_TYPE, account.type);
    builder.withValue(RawContacts.SYNC1, username);
    operationList.add(builder.build());

    builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
    builder.withValueBackReference(CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0);
    builder.withValue(Data.MIMETYPE, CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
    builder.withValue(CommonDataKinds.StructuredName.DISPLAY_NAME, name);
    operationList.add(builder.build());

    builder = ContentProviderOperation.newInsert(Data.CONTENT_URI);
    builder.withValueBackReference(Data.RAW_CONTACT_ID, 0);
    builder.withValue(Data.MIMETYPE, "vnd.android.cursor.item/vnd.org.c99.SyncProviderDemo.profile");
    builder.withValue(Data.DATA1, username);
    builder.withValue(Data.DATA2, "SyncProviderDemo Profile");
    builder.withValue(Data.DATA3, "View profile");
    operationList.add(builder.build());

后跟

mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);

创建新联系人,但不会在联系人中显示,但如果我按照Google中的联系人进行过滤并搜索该联系人,我就能看到该联系人。

任何人都可以告诉我原因,提前谢谢

3 个答案:

答案 0 :(得分:1)

我认为这是解决方案Android: Enable imported account contacts programmatically。您应指定UNGROUPED_VISIBLE = 1以使新联系人可见。

答案 1 :(得分:0)

所有字段都需要MimeTypes。设置它们并检查

试试这个

<强> Android Contacts - Update Note

答案 2 :(得分:0)

更改此行:

builder.withValueBackReference(CommonDataKinds.StructuredName.RAW_CONTACT_ID, 0);

要:

builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);

将此块添加到Manifest.xml中的活动:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="vnd.android.cursor.item/vnd.org.c99.SyncProviderDemo.profile" />
</intent-filter>

这解决了我的问题,但在Android 5中无效。