I am trying to show multiple rows as my app also support chat and call services. I want to show same like whatsap is doing as shown in below image.
I have implemented the sync adapter and all the other things using some help from different blogs. I have successfully added one row but i want multiple rows as we can see whatsap in that picture. I want to show multiple rows as shown in the picture.
Please see this for better understanding
ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
builder.withValue(RawContacts.ACCOUNT_NAME, Constants.ACCOUNT_NAME);
builder.withValue(RawContacts.ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
builder.withValue(RawContacts.SYNC1, contact.name);
ops.add(builder.build());
builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0);
builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/com.example.ajay.contacts_4");
builder.withValue(ContactsContract.Data.DATA1, contact.name);
builder.with Value(ContactsContract.Data.DATA2, "SyncProviderDemo Profile");
builder.withValue(ContactsContract.Data.DATA3, "View profile");
ops.add(builder.build());
try {
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (Exception e) {
e.printStackTrace();
}
I was inserting only for one time using ContentProviderOperation.newInsert as you can see in questions. But when i add multiple time for same contact and then apply the batch. Then one contact contains multiple rows.
builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/com.example.ajay.contacts_4"); builder.withValue(ContactsContract.Data.DATA1, contact.name); builder.with Value(ContactsContract.Data.DATA2, "SyncProviderDemo Profile"); builder.withValue(ContactsContract.Data.DATA3, "Call " + number); ops.add(builder.build());
builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI); builder.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0); builder.withValue(ContactsContract.Data.MIMETYPE, "vnd.android.cursor.item/com.example.ajay.contacts_4"); builder.withValue(ContactsContract.Data.DATA1, contact.name); builder.with Value(ContactsContract.Data.DATA2, "SyncProviderDemo Profile"); builder.withValue(ContactsContract.Data.DATA3, "Message" + number); ops.add(builder.build()); try { resolver.applyBatch(ContactsContract.AUTHORITY, ops); } catch (Exception e) { e.printStackTrace(); }