0
我想从我的联系人列表中永久删除联系人。 我正在使用以下代码。如何从联系人列表中删除联系人号码?
public boolean deleteContact(String phone, String name) {
System.out.println("name :: "+name +" "+phone);
Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(phone));
Cursor cur = context.getContentResolver().query(contactUri, null, null,
null, null);
try {
if (cur.moveToFirst()) {
do {
if (cur.getString(
cur.getColumnIndex(PhoneLookup.DISPLAY_NAME))
.equalsIgnoreCase(name)) {
String lookupKey = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_LOOKUP_URI,
lookupKey);
int i = context.getContentResolver().delete(uri, null, null);
System.out.println("i :::: "+i);
return true;
}
} while (cur.moveToNext());
}
} catch (Exception e) {
System.out.println(e.getStackTrace());
}
return false;
}
在我的移动联系人中,我有一个名为“SIRI”的联系人,有两个手机号码。上面的代码删除了两个数字。我想只删除选定的号码,而不是两个号码。
如果有两个数字,名字的意思是我想删除选定的号码不是名称和其他号码也。感谢您的回复。 – Siri