ContactsContract.Data.RAW_CONTACT_ID   vs.
ContactsContract.Data.CONTACT_ID
Can anyone please explain how these two IDs are different.

I'm having very strange merge issues when I try to add contacts
programmatically, (phone numbers that I mean to set to one contact,
end up in another for example) and I wonder if it doesn't have to do
with these IDs and using the wrong ones.

Both RAW_CONTACT_ID and CONTACT_ID are documented as "A reference to
the _ID that this data belongs to." very confusing.
How are we as developers supposed to figure out how to use these two
separate IDs when they are documented identically?


For example I create a brand new contact like so? :
// (please pay attenion to use of Data RAW_CONTACT_ID vs. CONTACT_ID)
//====
ArrayList<ContentProviderOperation> ops = new
ArrayList<ContentProviderOperation>();
                
ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
                                .withValue(RawContacts.ACCOUNT_TYPE, 
toAcctType).withValue(
                                                RawContacts.ACCOUNT_NAME, 
toAcct).build());
                ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
                                .withValueBackReference(Data.RAW_CONTACT_ID, 
0).withValue(
                                                Data.MIMETYPE, 
StructuredName.CONTENT_ITEM_TYPE)
                                .withValue(StructuredName.DISPLAY_NAME, 
fullName).build());
                ContentProviderResult[] insertResult = null;
                try {
                        insertResult = 
curContext().getContentResolver().applyBatch(
                                        ContactsContract.AUTHORITY, ops);
                } catch (Exception e) {
                        e.printStackTrace();
                }
                Uri newUri = insertResult[0].uri;
//====

Can I now add an email like so?

//====
                ContentValues values = new ContentValues();
                values.clear();
                values.put(Data.RAW_CONTACT_ID, ContentUris.parseId(newUri)); 
//or
should this Data.CONTACT_ID <----------??
                values.put(Data.MIMETYPE,
                                
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
                values.put(ContactsContract.CommonDataKinds.Email.DATA, 
someEmail);
                values.put(ContactsContract.CommonDataKinds.Email.TYPE, 
emailType);
                if (emailType == BaseTypes.TYPE_CUSTOM) {
                        values.put(ContactsContract.CommonDataKinds.Email.LABEL,
emailLabel);
                }
                curContext().getContentResolver().insert(Data.CONTENT_URI, 
values);
//====


A question for the Google devs: When we might see some real API
documentation for ContactContracts? The bare bones JavaDocs aren't
really sufficient to understand all of the complexities of this API.

Thanks a bunch.

Jake

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

Reply via email to