安卓:添加exsting联系人作为喜爱的联系? [英] Android: Adding exsting contacts as favourite contact?
问题描述
我有一个的ListView中,我得到手机的所有联系人。 ListView中我已经把一个按钮并单击该按钮的接触应该在收藏并再次单击应该从收藏夹中删除被加入。结果在这里,我找到了code,以添加收藏标记新联系人。但如何做到这一点的点击button.i这个code曾尝试:
I have one ListView in which i am getting all contacts of phone. in ListView i have put the one button and on clicking on that button that contact should be added in favourites and on clicking again that should be removed from favourites.
Here i found the code to add new contact with favourite tag.but how to do this on clicking on button.i have tried with this code:
code:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
int rawContactInsertIndex = ops.size();
ops.add(ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI)
.withValue(RawContacts.ACCOUNT_TYPE, null)
.withValue(RawContacts.ACCOUNT_NAME, null)
.withValue(RawContacts.STARRED, true).build());
ops.add(ContentProviderOperation
.newUpdate(ContactsContract.Data.CONTENT_URI)
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,
rawContactInsertIndex)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, "91-0000000002").build());
ops.add(ContentProviderOperation
.newUpdate(Data.CONTENT_URI)
.withValueBackReference(Data.RAW_CONTACT_ID,
rawContactInsertIndex)
.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
.withValue(StructuredName.DISPLAY_NAME, "Maulik patel").build());
使用这个code所有联系人添加到收藏夹结果
谢谢
Using this code all contacts are added to the favourite
thanks
推荐答案
下面是什么终于为我工作收藏特定联系人。
Here what is finally work for me to favourite specific contact.
ContentValues values = new ContentValues();
String[] fv = new String[] { "juned" };
values.put(Contacts.STARRED, 1);
getContentResolver().update(Contacts.CONTENT_URI, values,
Contacts.DISPLAY_NAME + "= ?", fv);
只是改变了1比0的不喜欢的。
just change the 1 to 0 for unfavorite.
这篇关于安卓:添加exsting联系人作为喜爱的联系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!