我务实地创建的android手机联系人组中没有删除选项。请帮我。我不知道如何删除电话的联系人组。默认情况下,电话联系人下有“家庭”、“朋友”和“工作”3 个组,出于测试目的,我创建了一个名为“测试”的组并为该组分配了一个联系人。现在的问题是,我没有看到删除此自定义组的任何选项。任何想法?
group="Test";
if (group != null) {
String GroupId = getGroupId();
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID, GroupId)
.build());
}
private String getGroupId()
{
String GroupId = ifGroup(group);
if (GroupId == null)
{
ArrayList<ContentProviderOperation> opsGroup = new ArrayList<ContentProviderOperation>();
opsGroup.add(ContentProviderOperation.newInsert(ContactsContract.Groups.CONTENT_URI)
.withValue(ContactsContract.Groups.TITLE, group)
.withValue(ContactsContract.Groups.GROUP_VISIBLE, true)
.withValue(ContactsContract.Groups.DELETED, true)
.withValue(ContactsContract.Groups.ACCOUNT_NAME, group)
.withValue(ContactsContract.Groups.ACCOUNT_TYPE, group)
.build());
try
{
getContentResolver().applyBatch(ContactsContract.AUTHORITY, opsGroup);
} catch (Exception e)
{
e.printStackTrace();
}
}
return ifGroup(group);
}
//### Function return group id by Group Title
private String ifGroup(String $name)
{
String selection = ContactsContract.Groups.DELETED + "=? and " + ContactsContract.Groups.GROUP_VISIBLE + "=?";
String[] selectionArgs = { "0", "1" };
Cursor cursor =getContentResolver().query(ContactsContract.Groups.CONTENT_URI, null, selection, selectionArgs, null);
cursor.moveToFirst();
int len = cursor.getCount();
String GroupId = null;
for (int i = 0; i < len; i++)
{
String id = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups._ID));
String title = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE));
if (title.equals(group))
{
GroupId = id;
break;
}
cursor.moveToNext();
}
cursor.close();
return GroupId;
}