1

I'm new to android dev, so I may get the whole concept totally wrong. I want to delete a specific entry from RawContact directory entry. Here is code that I have:

Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
         Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
         Cursor c = getContentResolver().query(entityUri,
                  new String[]{RawContacts._ID, Entity.DATA_ID, Entity.MIMETYPE,CommonDataKinds.GroupMembership.GROUP_SOURCE_ID},
                  null, null, null);

using cursor c I get appropriate Entity.DATA_ID. After that I try to delete an entry:

 getContentResolver().delete(entityUri,Entity.DATA_ID+"=?",
                  new String[]{id});

and get an error:

java.lang.UnsupportedOperationException: URI: content://com.android.contacts/raw_contacts/2709/entity

What am I doing wrong?

UPD 1 I am trying to remove group membership entry.

Nikolay R
  • 957
  • 2
  • 11
  • 22

2 Answers2

2

Please give a more complete explanation of what you're trying to do. You say that you want to "delete a specific entry from RawContact directory entry.", which is confusing? Do you want to

a) delete a raw contact? b) delete a set of raw contacts? c) delete all of the data rows for a single raw contact? d) delete all of the data rows for a set of raw contacts?

or do you want to do something with group membership?

In any event, I think you've constructed the URI backwards. Try appending Entity.CONTENT_DIRECTORY before the rawContactId. I know that the documentation doesn't say this, but the documentation is not well-written.

A better alternative would be to use the ContactsContract.RawContactEntity table.

Joe Malin
  • 8,621
  • 1
  • 23
  • 18
  • Joe, thank you. I want to remove groupmembership entry, that's correct. What is the right way to do it? Thank you for your suggestion - I will try it. BTW - what do you mean backwards - what is correct ? I was copypasting sample from documentation. Should it look like: raw_contacts/entity/2709? – Nikolay R Dec 20 '12 at 20:29
  • BTW http://developer.android.com/reference/android/provider/ContactsContract.RawContactsEntity.html says: It is a strictly read-only table. Is it possible to delete from it? – Nikolay R Dec 20 '12 at 22:15
  • Unfortunately reversing did not work: java.lang.IllegalArgumentException: URI: content://com.android.contacts/raw_contacts/entity/2709 – Nikolay R Dec 21 '12 at 07:54
0

Looks like I was using the wrong URI. Also I switched to a "new" way of modifying the table:

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

             ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
                      .withSelection(Data._ID + "=?", new String[]{i})
                      .build());
             getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
Nikolay R
  • 957
  • 2
  • 11
  • 22