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.

有帮助吗?

解决方案 2

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top