1

当我从联系人中列出组时,我总是只从显示的 google 中获得会员资格,而不是LOCAL GROUP中的会员资格(仅限电话)。我想确定本地存储在手机上。它是如何工作的?

我使用这个函数来获取可用的组:

public String[] getAvailableContactGroups()
{
    ArrayList<String> groups = new ArrayList<String>();

    Cursor groupCursor = getResolver().query(
            ContactsContract.Groups.CONTENT_SUMMARY_URI,
            new String[]
            {
                    ContactsContract.Groups._ID, ContactsContract.Groups.SUMMARY_COUNT,
                    ContactsContract.Groups.NOTES, ContactsContract.Groups.TITLE,
                    ContactsContract.Groups.GROUP_VISIBLE
            }, 
            null, null, null);

    while (groupCursor.moveToNext())
    {
        final String groupName = groupCursor.getString(groupCursor.getColumnIndex(ContactsContract.Groups.TITLE));
        // ...
        groups.add(groupName);
    }
    groupCursor.close();

    Log.i(TAG, "available groups: " + groups.toString());

    return groups.toArray(new String[groups.size()]);
}

结果仅显示来自 google 帐户的组。

此函数用于获取联系人的组成员资格:

public ArrayList<Long> getGroupIdsForContact(Long contactId)
{
    final Uri uri = Data.CONTENT_URI;
    final String where = String.format("%s = ? AND %s = ?", Data.MIMETYPE, GroupMembership.CONTACT_ID);

    ArrayList<Long> ar = new ArrayList<Long>();

    final String[] whereParams = new String[]
    {
            GroupMembership.CONTENT_ITEM_TYPE,
            Long.toString(contactId),
    };

    final String[] selectColumns = new String[]
    {
        GroupMembership.GROUP_ROW_ID,
    };

    Cursor groupIdCursor = getResolver().query(uri, selectColumns, where, whereParams, null);
    try
    {
        while (groupIdCursor.moveToNext())
        {
            ar.add(groupIdCursor.getLong(0));
        }
    }
    finally
    {
        groupIdCursor.close();
    }

    Log.i(TAG, "user " + contactId + " is in groups: " + ar.toString());

    return ar;
}

这很好用,但不适用于本地联系人。请问有人可以帮我吗?

4

0 回答 0