Android 2.0的如何取得联络组显示的姓名和号码 [英] Android 2.0 How to get display name and number in a contact group

查看:192
本文介绍了Android 2.0的如何取得联络组显示的姓名和号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个给定组ID的联系人列表中的 ID 的:

I get a list of contacts in a given group id by 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());
}

但似乎无法正常工作。

But it seems that does not work correctly.

推荐答案

也许你缺少的媒体类型。

Probably you are missing the 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");

这篇关于Android 2.0的如何取得联络组显示的姓名和号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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