【问题标题】:Get contact group from contacts从联系人中获取联系人组
【发布时间】:2014-09-10 07:36:57
【问题描述】:

我有 id 联系人,我怎样才能找到他的群组(朋友、家人、收藏夹...)?

我试试:

String where = String.format("%s = ?", ContactsContract.Groups._ID);
    String[] whereParams = new String[]{id};
    String[] selectColumns = {ContactsContract.Groups.TITLE};
    Cursor c = cr.query(Data.CONTENT_URI, selectColumns, where, whereParams, null); //THIS_LINE

    Log.d("Log", "cursor GROUP " + c.getString(0));
    c.close();

但我在 THIS_LINE 中有例外:

E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-24188
Process: com.app.contactsmyclients, PID: 22499
java.lang.IllegalArgumentException: Invalid column title
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
        at android.content.ContentProviderProxy.query(ContentProviderNative.java:463)
        at android.content.ContentResolver.query(ContentResolver.java:476)

【问题讨论】:

标签: android android-contacts


【解决方案1】:

试试这个,它对我来说很好用:

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 找到

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 2013-12-16
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 2017-09-07
    相关资源
    最近更新 更多