librelist archives

« back to archive

Deleting Contacts from Android

Deleting Contacts from Android

From:
Simon MacDonald
Date:
2011-05-06 @ 14:46
Hi all,

I'm having a problem trying to delete a contact from my Android device.
 When I delete the contact by using the following code:

 ArrayList<ContentProviderOperation> ops = new
 ArrayList<ContentProviderOperation>();


 ops.add(ContentProviderOperation.newDelete(ContactsContract.Data.
CONTENT_URI)

                          .withSelection(ContactsContract.Data.CONTACT_ID +
"=?",

                           new String[]{id})

                          .build());

 try {

 mApp.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

 } catch (RemoteException e) {

 Log.e(LOG_TAG, e.getMessage(), e);

 } catch (OperationApplicationException e) {

 Log.e(LOG_TAG, e.getMessage(), e);

 }

or:

     int result = mApp.getContentResolver().delete(ContactsContract.Data.
CONTENT_URI,

      ContactsContract.Data.CONTACT_ID + " = ?",

      new String[] {id});

The contact seems to be replaced by one called "(Unknown)".  Does anyone
know why this is the case and if there is anything I can do so that the
contact is deleted cleanly and I don't seen "(Unknown)" in the contact app
anymore?

Thanks...

Simon Mac Donald
http://hi.im/simonmacdonald