可以从收到的电话号码获取 ID,但不能从群组获取 ID
我已成功从拨入的电话号码中获取 ID 和姓名。我想要查看该 ID 属于哪些组。我尝试了以下操作:
//Search for the information about the phone number, save the goupID(s)
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(aNumber));
ContentResolver cr = mService.getContentResolver();
Cursor myCursor = cr.query(uri, new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME},null, null, null);
myCursor.moveToFirst();
//String contactID = myCursor.getString(myCursor.getColumnIndex(PhoneLookup._ID));
String contactID = myCursor.getString(myCursor.getColumnIndex(ContactsContract.Contacts._ID));
myCursor.close();
//Use the cursor to query for group with help of ID from the Phone look up
myCursor = cr.query(ContactsContract.Groups.CONTENT_URI,
new String[]{ContactsContract.Groups._ID},
ContactsContract.Groups._ID + " = ?",
new String[]{contactID},
null);
//Contact may be in more than one group
nbrOfGroups = myCursor.getCount();
groupName = new String [nbrOfGroups];
问题是第二个查询,我想使用在电话查找中找到的 contactID 来查看 contactID 属于哪些组。结果是没有组,尽管该联系人已添加到我的联系人中的组中。
有什么想法吗? :)
I have succeded in getting the ID and name from a phone number that is calling in. What I would like to to is to see which groups this ID belongs to. I have tried the following:
//Search for the information about the phone number, save the goupID(s)
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(aNumber));
ContentResolver cr = mService.getContentResolver();
Cursor myCursor = cr.query(uri, new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME},null, null, null);
myCursor.moveToFirst();
//String contactID = myCursor.getString(myCursor.getColumnIndex(PhoneLookup._ID));
String contactID = myCursor.getString(myCursor.getColumnIndex(ContactsContract.Contacts._ID));
myCursor.close();
//Use the cursor to query for group with help of ID from the Phone look up
myCursor = cr.query(ContactsContract.Groups.CONTENT_URI,
new String[]{ContactsContract.Groups._ID},
ContactsContract.Groups._ID + " = ?",
new String[]{contactID},
null);
//Contact may be in more than one group
nbrOfGroups = myCursor.getCount();
groupName = new String [nbrOfGroups];
The problem is tha second query, where I would like to use the contactID that i found in the phone lookup, to see which groups that contacID belongs to. The result is no group, although the contact is added to a group in my contacs.
Any ideas? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Groups._ID 与Contact ID 不同,它是存储所有组信息的表的索引。获取联系人 ID 后,您应该使用组成员资格 mimetype 从数据表中获取该联系人的所有组成员资格。
获取组 ID 后,您可以查询组表以获取所有组的标题,
尝试使用此代码
Groups._ID is not same as Contact ID, instead it is the index for the table storing all the group information. After you get the contact ID you should get all the group membership for that contact from the data table by using the Group membership mimetype.
After getting the group ids you can query the Groups table to get the TITLE for all the groups
try with this code