Hello everyone!
Yes, I know there are plenty of troubles in the current contacts API,
but still I want to ask one more question on the subject. I have
succesfully managed to add contact with some details to the phone
contacts list using this code (it may not work out-of-the-box since I
copy-pasted it from different parts of my program, but it's working
there)


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

Uri.Builder builder = RAW_CONTACT_URI.buildUpon();

ContentProviderOperation operation =
ContentProviderOperation.newInsert(builder.build())
                                                          
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,
"[email protected]")
                                                          
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME,
"com.google")
                                                          .build();
operations.add(operation);

ContentProviderOperation.Builder cpBuilder;

Uri.Builder uriBuilder =
ContactsContract.Data.CONTENT_URI.buildUpon();

cpBbuilder = ContentProviderOperation.newInsert(uriBuilder.build());

cpBuilder =
builder.withValue(CommonDataKinds.StructuredName.DISPLAY_NAME,
"Gugl1")
                                   .withValue(ContactsContract.Data.MIMETYPE,
 
CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);

operation = cpBuilder.build();

operations.add(operation);

resolver.applyBatch(ContactsContract.AUTHORITY, operations);

/*
...
contact is created, I get his id and add to some group
...
*/

operations.clear();

operations.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
                        .withValue(GroupMembership.RAW_CONTACT_ID, id)
                        .withValue(GroupMembership.GROUP_ROW_ID, SOME_GROUP_ID)
                        .withValue(Data.MIMETYPE,
GroupMembership.CONTENT_ITEM_TYPE)
                        .build());

resolver.applyBatch(ContactsContract.AUTHORITY, operations);

After this code works, I get a gmail contact listed on my phone, the
group is "Starred in Android", but no matter what I do after - edit(if
I edit it's displayed as gmail contact) it, open/close etc. - this
contact never appears on my Gmail's contact list. Maybe some
additional fields should be added to contact's record in order to make
it be synced with Gmail? I am confused. Please, help.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to