0
    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());

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

Ramji
  • 2,536
  • 7
  • 34
  • 54

3 Answers3

1

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

Community
  • 1
  • 1
Fedor
  • 43,261
  • 10
  • 79
  • 89
0

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.

Bayron
  • 21
  • 6
0

You need MimeTypes for all fields. Set them and check

try this too

Android Contacts - Update Note

Community
  • 1
  • 1
ngesh
  • 13,398
  • 4
  • 44
  • 60