获取属于特定组的联系人列表 [英] Get list of contacts belonging to a specific group

查看:69
本文介绍了获取属于特定组的联系人列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何获取Android中属于1个特定组的联系人列表吗?

Does anybody know how to get a list of contacts belonging to a 1 specific group in Android?

我需要这样的东西:

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);

这要求您已经具有组ID,并且可以通过查询ContactsContract.Groups来找到

this requires you to have the Group id already and that can be found by querying ContactsContract.Groups

这篇关于获取属于特定组的联系人列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆