Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a contact?

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<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());
like image 590
user408273 Avatar asked Aug 05 '10 09:08

user408273


People also ask

Why can't I delete contacts on my Iphone?

If you can't delete contacts means you might have Restrictions ON. Settings > Screen Time > Content & Privacy Restrictions > Contact : set to Allow Changes. Note: Content & Privacy Restrictions must be enabled to make changes. Go to the contact's card, then tap Edit.

How do I permanently delete a contact from my Iphone?

Delete a contactOpen Contacts and tap the contact that you want to delete. Tap Edit. Scroll Down and tap Delete Contact then tap Delete Contact again to confirm.


1 Answers

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);

like image 134
Karan Avatar answered Nov 01 '22 08:11

Karan