无法使用 ContentProviderOperation 删除整个联系人
我一直在处理 Android 联系人。我可以向他们展示并更新,但是 当我想删除任何一个时,它都没有完全删除。在通讯录中 应用程序显示为(未知),没有任何数据。这是我的例子:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
.withSelection(Data.CONTACT_ID + "=?", new String[]{selectedid})
.build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
我应该采取其他措施来完全删除联系人吗? 这些代码似乎删除了表 ContactsContract.Data 中的信息,但它没有删除表 ContactsContract.Contacts 或 ContactsContract.RawContacts 中相关的元素。我怎样才能完全删除联系人?
=================================================== ============================
另外,我尝试了已弃用的方法。它确实有效,但我不想这样做。这是示例代码:
ContentResolver contentResolver = m_cContent.getContentResolver();
contentResolver.delete(People.CONTENT_URI, People.NAME + "=?", new String[] { SelectedName });
如果我将此代码修改为
ContentResolver contentResolver = m_cContent.getContentResolver();
contentResolver.delete(ContactsContract.Contacts, ContactsContract.Contacts._ID + "=?", new String[] { Selectedid });
它没有效果。
这是否意味着只能通过姓名而不是 ID 来删除联系人? 我到底该怎么做才能删除联系人?
谢谢, 锚定
I have been working with Android contacts. I am able to show them, update but
when I want to delete any, it is not deleted completely. In Contacts
application is shown as (Unknown) without any data. Here is my example:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
.withSelection(Data.CONTACT_ID + "=?", new String[]{selectedid})
.build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
Should I do anything else to delete contact entirely?
It seems that these code delete info in table ContactsContract.Data but it does not delete element related in table ContactsContract.Contacts or ContactsContract.RawContacts.how can i do to delete an contact completely?
============================================================================
also, i tried deprecated method. It dose work, but i do not want to do so. Here is the sample code:
ContentResolver contentResolver = m_cContent.getContentResolver();
contentResolver.delete(People.CONTENT_URI, People.NAME + "=?", new String[] { SelectedName });
and if i modify this code to
ContentResolver contentResolver = m_cContent.getContentResolver();
contentResolver.delete(ContactsContract.Contacts, ContactsContract.Contacts._ID + "=?", new String[] { Selectedid });
It has no effect.
Does it mean that one can only delete a contact by name instead of by its id?
What on earth can i do to delete contact?
Thanks,
Enchor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正尝试通过从
数据
表中删除联系人的数据行来删除该联系人。那是行不通的。
一个联系人由多个原始联系人组成,每个原始联系人的数据都保存在
Data
表中。删除联系人时,所有原始联系人及其数据也会被删除。
这样做:
如果操作成功,deleted 将为 1。
You are trying to delete a contact by deleting its data rows from the
Data
table.That wouldn't work.
A contact is made up of several raw-contacts, each raw-contact has its data saved in the
Data
table.When deleting a contact, all raw-contacts get deleted as well, along with their data.
Do this:
deleted will be 1 if the operation succeeded.