I want to delete user name whose name is Leo. So I am putting delete query as follow
我想删除名称为Leo的用户名。所以我把删除查询如下
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
编辑:以上操作无效,因为该字段仅使用Contacts.CONTENT_URI读取您可以使用以下URI查看。 http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html
3 个解决方案
#1
1
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
In above link I can able to find the solution. I can able to delete contacts completely.
在上面的链接中,我能够找到解决方案。我可以完全删除联系人。
The problem is related to sync adapter.
该问题与同步适配器有关。
#2
1
To delete selected contacts from the contactDB we could use the following code.
要从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();
}
#3
0
I suppose you should state in Android manifest permission to WRITE_CONTACTS
. Look in http://developer.android.com/reference/android/Manifest.permission.html
我想你应该在Android清单中声明WRITE_CONTACTS。查看http://developer.android.com/reference/android/Manifest.permission.html
#1
1
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
In above link I can able to find the solution. I can able to delete contacts completely.
在上面的链接中,我能够找到解决方案。我可以完全删除联系人。
The problem is related to sync adapter.
该问题与同步适配器有关。
#2
1
To delete selected contacts from the contactDB we could use the following code.
要从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();
}
#3
0
I suppose you should state in Android manifest permission to WRITE_CONTACTS
. Look in http://developer.android.com/reference/android/Manifest.permission.html
我想你应该在Android清单中声明WRITE_CONTACTS。查看http://developer.android.com/reference/android/Manifest.permission.html