访问 Android 联系人组名称 [英] Accessing Android Contact Group Names

查看:27
本文介绍了访问 Android 联系人组名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我如何以编程方式获取联系人组存储在我们的安卓手机中?

Can you please tell me how to fetch contact groups programmatically stored in our android phone?

推荐答案

final String[] GROUP_PROJECTION = new String[] {
            ContactsContract.Groups._ID, ContactsContract.Groups.TITLE };
    cursor = getContentResolver().query(
    ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
            null, ContactsContract.Groups.TITLE);

            GlobalConfig.groupList.clear();
    Group g = new Group();
    g.GroupIdList += "0";
    g.setGroupTitle("ALL");
    GlobalConfig.groupList.add(g);
    while (cursor.moveToNext()) {

        String id = cursor.getString(cursor
                .getColumnIndex(ContactsContract.Groups._ID));

        String gTitle = (cursor.getString(cursor
                .getColumnIndex(ContactsContract.Groups.TITLE)));

        if (gTitle.contains("Group:")) {
            gTitle = gTitle.substring(gTitle.indexOf("Group:") + 6).trim();

        }
        if (gTitle.contains("Favorite_")) {
            gTitle = "Favorites";
        }
        if (gTitle.contains("Starred in Android")
                || gTitle.contains("My Contacts")) {
            continue;
        }

        Group gObj = new Group();

        int pos = GlobalConfig.GroupContainsTitle(gTitle);
        if (pos != -1) {
            gObj = GlobalConfig.groupList.get(pos);
            gObj.GroupIdList += "," + id;
            GlobalConfig.groupList.set(pos, gObj);

        } else {
            gObj.GroupIdList += id;
            gObj.setGroupTitle(gTitle);
            GlobalConfig.groupList.add(gObj);

        }

        // Log.d("GrpId  Title", gObj.getGroupIdList() +
        // gObj.getGroupTitle());
    }

这篇关于访问 Android 联系人组名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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