【问题标题】:Android 2.0 How to get display name and number in a contact groupAndroid 2.0 如何在联系人组中获取显示名称和号码
【发布时间】:2010-06-09 21:20:40
【问题描述】:

我通过 id 获得给定组 id 中的联系人列表:

Cursor cur = ctx.managedQuery(ContactsContract.Data.CONTENT_URI,
             new String[] { GroupMembership.GROUP_ROW_ID,
        GroupMembership.CONTACT_ID },
        GroupMembership.GROUP_ROW_ID + "=" + String.valueOf(id),
        null, null);

if (cur.moveToFirst()) {
    int groupIdx = cur.getColumnIndex(GroupMembership.GROUP_ROW_ID);
    int personIdx = cur.getColumnIndex(GroupMembership.CONTACT_ID);

    do {
        if (cur.getLong(groupIdx) == id) {
            Cursor ccur = ctx.getContentResolver().query( Phone.CONTENT_URI,
                new String[] {Phone.NUMBER, Phone.TYPE,
                Phone.DISPLAY_NAME },
                Phone.CONTACT_ID +"="+ contactId, 
                      null, null); 
            Log.e("Test: Number", ccur.getString(0))
            Log.e("Test: Name", ccur.getString(2))
        }
    } while (cur.moveToNext());
}

但似乎不能正常工作。

【问题讨论】:

    标签: android contacts android-2.0-eclair


    【解决方案1】:

    您可能缺少 mimetype。

    String where = ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + "="
                    + groupid + " AND "
                    + ContactsContract.CommonDataKinds.GroupMembership.MIMETYPE + "='"
                    + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "'";
    
            Cursor c = this.ctx.getContentResolver().query(
                    ContactsContract.Data.CONTENT_URI,
                    new String[] {
                            ContactsContract.CommonDataKinds.GroupMembership.RAW_CONTACT_ID,
                            ContactsContract.Data.DISPLAY_NAME
                    }, where, null, ContactsContract.Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
    

    【讨论】:

    猜你喜欢
    • 2015-11-11
    • 1970-01-01
    • 2011-09-13
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多