我当时在android 2.1 ContactContract上工作,当时我还没有将帐户(例如:gmail帐户)设置为android仿真器,因此新建了一个联系人,但无法在数据库中删除此联系人。
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
String[] args = new String[] {id};
ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
.withSelection(Data.CONTACT_ID + "=?", args)
.build());
ops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI)
.withSelection(RawContacts.CONTACT_ID + "=?", args)
.build());
ops.add(ContentProviderOperation.newDelete(Contacts.CONTENT_URI)
.withSelection(Contacts._ID + "=?", args)
.build());
最佳答案
从RawContacts删除联系人将从Data,Contacts表中删除数据。ArrayList ops = new ArrayList(); String[] args = new String[] {id};// if id is raw contact idops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).withSelection(RawContacts._ID + "=?", args) .build()); OR// if id is contact idops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).withSelection(RawContacts.CONTACT_ID + "=?", args) .build());getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);