我尝试使用以下代码删除指定号码的联系人:
private void removeContact(Context context, String phone) {
//context.getContentResolver().delete(Contacts.Phones.CONTENT_URI, phone, null);
context.getContentResolver().delete(Contacts.Phones.CONTENT_URI,
Contacts.PhonesColumns.NUMBER+"=?", new String[] {phone});
}
但我得到了这个异常(exception):
java.lang.UnsupportedOperationException: Cannot delete that URL: content://contacts/phones
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:130)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:110)
at android.content.ContentProviderProxy.delete(ContentProviderNative.java:362)
at android.content.ContentResolver.delete(ContentResolver.java:386)
您能告诉我如何解决我的问题吗?
Cảm ơn.
要删除所有联系人,请使用以下代码:
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
while (cur.moveToNext()) {
thử{
String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
System.out.println("The uri is " + uri.toString());
cr.delete(uri, null, null);
}
catch(Exception e)
{
System.out.println(e.getStackTrace());
}
}
要删除任何特定联系人,请修改查询
cr.delete(uri, null, null);
希望对你有帮助!
Tôi là một lập trình viên xuất sắc, rất giỏi!