I'd like to add a contact member to a group:
我想将联系会员添加到群组中:
values.put(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, groupId);
Currently I only have TITLE of this group, how do I get groupId
by this TITLE?
目前我只有这个TITLE的TITLE,我怎么得到这个TITLE的groupId?
2 个解决方案
#1
0
If what you want is to access groupId
by group name
you can call getContentResolver().query( ... )
on content provider by passing ContactsContract.Contacts.DISPLAY_NAME
column name and it respectivelyvalue.
如果您想要的是按组名访问groupId,您可以通过传递ContactsContract.Contacts.DISPLAY_NAME列名称及其值分别在内容提供者上调用getContentResolver()。query(...)。
Also you can look this seemed post
Getting Contact GroupName and GroupId
你也可以看看这个似乎发布了Get Contact GroupName和GroupId
#2
1
Ok, this is a full version of how to get the group id by its title. Basically it iterates all groups and compare titles to find its id.
好的,这是如何通过标题获取组ID的完整版本。基本上它迭代所有组并比较标题以找到它的id。
private String getGroupId(String groupTitle) {
Cursor cursor = getContentResolver().query(ContactsContract.Groups.CONTENT_URI,new String[]{ContactsContract.Groups._ID,ContactsContract.Groups.TITLE}, null, null, null);
cursor.moveToFirst();
int len = cursor.getCount();
String groupId = null;
for (int i = 0; i < len; i++) {
String id = cursor.getString(cursor.getColumnIndex(Groups._ID));
String title = cursor.getString(cursor.getColumnIndex(Groups.TITLE));
if (title.equals(groupTitle)) {
groupId = id;
break;
}
cursor.moveToNext();
}
cursor.close();
return groupId;
}
#1
0
If what you want is to access groupId
by group name
you can call getContentResolver().query( ... )
on content provider by passing ContactsContract.Contacts.DISPLAY_NAME
column name and it respectivelyvalue.
如果您想要的是按组名访问groupId,您可以通过传递ContactsContract.Contacts.DISPLAY_NAME列名称及其值分别在内容提供者上调用getContentResolver()。query(...)。
Also you can look this seemed post
Getting Contact GroupName and GroupId
你也可以看看这个似乎发布了Get Contact GroupName和GroupId
#2
1
Ok, this is a full version of how to get the group id by its title. Basically it iterates all groups and compare titles to find its id.
好的,这是如何通过标题获取组ID的完整版本。基本上它迭代所有组并比较标题以找到它的id。
private String getGroupId(String groupTitle) {
Cursor cursor = getContentResolver().query(ContactsContract.Groups.CONTENT_URI,new String[]{ContactsContract.Groups._ID,ContactsContract.Groups.TITLE}, null, null, null);
cursor.moveToFirst();
int len = cursor.getCount();
String groupId = null;
for (int i = 0; i < len; i++) {
String id = cursor.getString(cursor.getColumnIndex(Groups._ID));
String title = cursor.getString(cursor.getColumnIndex(Groups.TITLE));
if (title.equals(groupTitle)) {
groupId = id;
break;
}
cursor.moveToNext();
}
cursor.close();
return groupId;
}