在 Android 2.1+ 中检索联系人组 ID 时出错
基本上,事情更像是黑白的,在一部手机(Galaxy S)上工作正常,而在另一部手机(Nexus 手机,当然是我客户的)上则不然。
首先,我显示具有电话号码的联系人列表。用户选择备份联系人,我尝试加载所有联系人信息以将其存储在本地数据库中
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
}
使用此 id 我尝试获取联系人的组 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();
}
好吧,通过添加新联系人进行测试,在我的手机上我得到 groupId=1 ,意思是系统:我的联系人。在 Nexus One 上,我的组 ID 为空。当然,在我的手机上恢复工作正常,而在另一部手机上,联系人不可见,因为它不属于任何可见的组...
有什么想法吗?
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 Contacts. 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是一个误解...我需要获取 RAW Contact ID 并且我使用了 ContactID..所以,在搜索 GroupId 之前我需要获取 Contact Raw Id
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