Android 2.0 如何获取联系人组中的显示名称和号码

发布于 2024-09-04 19:35:14 字数 954 浏览 3 评论 0原文

我通过 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());
}

但似乎无法正常工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携君以终年 2024-09-11 19:35:14

可能您缺少 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");

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文