当我列出来自联系人的群组时,我始终只会从谷歌显示的会员资格中获得会员资格,但绝不会获得 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;
}
这很有效,但不适用于本地联系人。请有人帮帮我吗?