开发者

added contact does not show up in Contacts in 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.new开发者_StackOverflow社区Insert(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());

followed by a

mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList);

Creates a new contact, but does not show in the contacts, but If i filter by contacts in google and search for that I am able to see the contact.

Can anyone tell me why, thanks in advance


I think that's the solution Android: Enable imported account contacts programmatically. You should specify UNGROUPED_VISIBLE=1 to make new contacts visible.


You need MimeTypes for all fields. Set them and check

try this too

Android Contacts - Update Note


Change this line:

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

To:

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

And add this block to a activity in the 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>

This solved my problem, but in Android 5 is not working.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜