在Android更新联系方式 [英] update contact details on Android
问题描述
我想我的code更新的联系方式(如姓名,电话号码,电子邮件,组织细节,等等)在Android通讯录。我是在修改了一些(姓名,电话号码和电子邮件是具体的)成功,但不是全部。
每当我试着联系人更新组织详细信息(Contacts.Organizations.COMPANY和Contacts.Organizations.TITLE)我的应用程序引发的除了
java.lang.UnsupportedOperationException:无法更新网址:内容://联系人/人/ 69 /组织/ 69
在code片断如下:
开放的基本URI = ContentUris.withAppendedId(People.CONTENT_URI,69);
开放的我们的uri = Uri.withAppendedPath(基本URI,People.Phones.CONTENT_DIRECTORY);
光标C = this.getContentResolver()查询(URI,
新的String [] {Contacts.Organizations._ID,Contacts.Organizations.COMPANY,Contacts.Organizations.TITLE},
NULL,NULL,NULL);
如果(c.getCount()大于0){
的uri = ContentUris.withAppendedId(URI,c.getString(0));
ContentValues VAL1 =新ContentValues();
val1.put(Contacts.Organizations.COMPANYARW);
val1.put(Contacts.Organizations.TYPE,Contacts.Organizations.TYPE_WORK);
val1.put(Contacts.Organizations.TITLEABCDEF);
this.getContentResolver()插入(URI,VAL1)。
为了更新您需要了解该领域的现有标识联系人的任何数据。然后我用生成器类,以获得不同的领域,我想更新单独的ContentProviderOperation对象,将它们添加到ArrayList,然后使用ContentProvider.applyBatch()方法
I would like my code to update contact details (like name, phone number, email, organization details, etc) in the android contact book. I was successful in modifying a few (name, phone number and email to be specific) but not all.
Whenever I try to update the organization details (Contacts.Organizations.COMPANY and Contacts.Organizations.TITLE) for a contact my app throws an exception
java.lang.UnsupportedOperationException: Cannot update URL: content://contacts/people/69/organizations/69
the code snippet is as follows:
Uri baseUri = ContentUris.withAppendedId(People.CONTENT_URI, 69);
Uri uri = Uri.withAppendedPath(baseUri, People.Phones.CONTENT_DIRECTORY);
Cursor c = this.getContentResolver().query(uri,
new String[] { Contacts.Organizations._ID, Contacts.Organizations.COMPANY,Contacts.Organizations.TITLE},
null, null, null);
if(c.getCount() > 0) {
uri = ContentUris.withAppendedId(uri, c.getString(0));
ContentValues val1 = new ContentValues();
val1.put(Contacts.Organizations.COMPANY, "arw");
val1.put(Contacts.Organizations.TYPE, Contacts.Organizations.TYPE_WORK);
val1.put(Contacts.Organizations.TITLE, "abcdef");
this.getContentResolver().insert(uri, val1);
In order to update any data in the contacts you need to know the existing id for that fields. Then I used the Builder class to obtain separate ContentProviderOperation objects for the various fields I wanted to update, add them to an arrayList and then use the ContentProvider.applyBatch() method
这篇关于在Android更新联系方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!