Error retrieving contact group id in Android 2.1+
Basically things are more like black and white, on one phone (Galaxy S) works fine and on another (Nexus one, my client's of course) it doesn't.
First I show a list of Contacts that have phone numbers. The user chooses to backup a contact and I try to load all contact info to store it in a local database
cursor = contentResolver.query(ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id), null, null, null, null);
if (cursor != null && cursor.getCount() >0)
{
cursor.moveToFirst();
id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID));
//get all the things I need like phones, picture, etc
}
Using this id I try to get the contact's group id
cursor = contentResolver.query(ContactsContract.Data.CONTENT_URI,
null,
ContactsContract.Data.RAW_CONTACT_ID
+ "="
+ id
+ " AND "
+ ContactsContract.Data.MIMETYPE
+ "='"
+ ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE
+ "'",
null,
null);
if (cursor != null && cursor.getCount() >0)
{
cursor.moveToFirst();
groupId= cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DATA1));
cursor.close();
}
Well, testing by adding a new contact, on my phone I get groupId=1, meaning System:My Con开发者_运维知识库tacts. On the Nexus One, I get null for group id. Of course, restoring in on my phone works fine, and on the other phone, the contact is not visible because it doesn't belong to any visible groups...
Any ideas ?
The problem was a misunderstanding... I needed to get RAW Contact ID and I used ContactID.. so, before searching for GroupId I needed to obtain Contact Raw Id
精彩评论