views:

296

answers:

1

I'm working at android 2.1 ContactContract, when I had not set account(for example: gmail account) to android emulator then , new a contact , but could not delete this contact at DB.

ArrayList ops = new ArrayList(); 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());

+1  A: 

Deleting the contact from RawContacts will delete the data from Data, Contacts table.

ArrayList ops = new ArrayList(); String[] args = new String[] {id}; 
// if id is raw contact id
ops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).withSelection(RawContacts._ID + "=?", args) .build()); 
    OR
// if id is contact id
ops.add(ContentProviderOperation.newDelete(RawContacts.CONTENT_URI).withSelection(RawContacts.CONTACT_ID + "=?", args) .build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

Karan
Dear Karan, I had a try ,although this method could delete the contact ,it also have some problems. The contacts' information is saved in the file "contacts2.db" , I searched this db file, the contact is deleted in "contacts" table, but is not deleted at "data" table, can you delete a contact completely?