机器人 - 获取属于特定组的联系人列表 [英] Android - Get list of contacts belonging to a specific group
本文介绍了机器人 - 获取属于特定组的联系人列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道如何得到属于1特定组的Android联系人列表?
我需要的是这样的:
SELECT * FROM接触,其中GROUP_ID =1234
我能够通过这样的事情让所有的联系人或所有组的列表:
光标groupCursor = cr.query(ContactsContract.Contacts.CONTENT_URI,NULL,NULL,NULL,NULL);
最后的ArrayList<字符串>联系人=新的ArrayList<字符串>();
而(groupCursor.moveToNext()){
字符串名称= groupCursor.getString(groupCursor.getColumnIndex(ContactsContract.Constacts.DisplayName));
contacts.add(名称);
}
解决方案
这是我用的,它为我工作正常
乌里groupURI = ContactsContract.Data.CONTENT_URI;
的String []投影=新的String [] {
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,
ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID};
光标C = managedQuery(groupURI,
投影,
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID +=+ GROUPID,
NULL,NULL);
这需要你有组ID已经并能够通过查询ContactsContract.Groups中找到
Does anybody know how to get a list of contacts belonging to a 1 specific group in Android?
I need something like this:
Select * from contacts where group_id = "1234"
I am able to get a list of all contacts OR all groups by using something like this:
Cursor groupCursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
final ArrayList<String> contacts = new ArrayList<String>();
while(groupCursor.moveToNext()) {
String name = groupCursor.getString(groupCursor.getColumnIndex(ContactsContract.Constacts.DisplayName ));
contacts.add(name);
}
解决方案
this is what i use and it works fine for me
Uri groupURI = ContactsContract.Data.CONTENT_URI;
String[] projection = new String[]{
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID ,
ContactsContract.CommonDataKinds.GroupMembership.CONTACT_ID};
Cursor c = managedQuery(groupURI,
projection,
ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID+"="+groupID,
null,null);
this requires you to have the Group id already and that can be found by querying ContactsContract.Groups
这篇关于机器人 - 获取属于特定组的联系人列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文