3

I want to delete user name whose name is Leo. So I am putting delete query as follow

    int i = getContentResolver().delete(Contacts.CONTENT_URI, Contacts.DISPLAY_NAME +"= 'Leo'",null);
    System.out.println("rows deleted "+i);
but it returns "rows deleted 0"

what is wrong with it.

Edits : The above is not working because the field is read only using Contacts.CONTENT_URI You can see using following URI. http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html

4

3 に答える 3

1

選択した連絡先を contactDB から削除するには、次のコードを使用できます。

ContentResolver cr = getContentResolver();
                String where = ContactsContract.Data.DISPLAY_NAME + " = ? ";
                String[] params = new String[] {nam};

                ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
                ops.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI)
                        .withSelection(where, params)
                        .build());
                try {
                    cr.applyBatch(ContactsContract.AUTHORITY, ops);
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (OperationApplicationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
于 2012-05-18T04:53:45.243 に答える
1

http://developer.android.com/resources/samples/SampleSyncAdapter/index.html

上記のリンクで解決策を見つけることができます。連絡先を完全に削除できます。

問題は同期アダプターに関連しています。

于 2011-01-25T06:03:04.080 に答える
0

へのアクセス許可を Android マニフェストに記載する必要があると思いますWRITE_CONTACTShttp://developer.android.com/reference/android/Manifest.permission.htmlを見てください

于 2011-01-18T07:18:35.123 に答える