In Android, when the user selects one contact using the contact picker, you get only the CONTACT_ID field. But for updating some contact info, you need to edit the raw contact data. To do so, you have to know the RAW_CONTACT_ID. Is this correct so far?
So how do you get the RAW_CONTACT_ID that you need for updating data when you have only the CONTACT_ID? Like this … ?
String[] projection = new String[] { ContactsContract.RawContacts._ID };
String where = ContactsContract.RawContacts.CONTACT_ID + " = ?";
String[] selection = new String[] { String.valueOf(contactId) };
Cursor c = getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, projection, where, selection, null);
But this way you will get all the RAW_CONTACT_IDs belonging to the picked user, right? Which one is then the raw contact that I should update?
If you want to say “It’s up to you”: It’s all the same to me. I just want to put my data anywhere, in any raw contact that can hold the data.
There’s no perfect answer. But the easiest, and probably, most correct is to use the google account.
Which you can do by selecting on the ACCOUNT_TYPE which will be “com.google” for the google account. As there can be many google accounts on the phone just choose the first one (or the one with most contacts).