【发布时间】:2015-07-22 16:10:00
【问题描述】:
我想从我的安卓手机中删除所有以“AAA”开头或包含“AAA”的联系人。这是我尝试过的:
private void deleteContact(String name) {
ContentResolver cr = getContentResolver();
String where = ContactsContract.Data.DISPLAY_NAME + " = ? ";
String[] params = new String[] {"AAAA"};
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
.withSelection(where, params)
.build());
Log.e(",,,,",String.valueOf(ops.get(0)));
try {
cr.applyBatch(ContactsContract.AUTHORITY, ops);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(NativeContentProvider.this, "Deleted the contact with name '" + name +"'", Toast.LENGTH_SHORT).show();
}
但是失败了。请给我一些想法,以便我可以继续我的项目。
【问题讨论】:
-
失败了怎么办?请详细说明您遇到了什么错误或问题。
标签: android android-contentprovider android-contacts