我希望我的代码更新android 通讯录中的联系方式(如姓名、电话号码、电子邮件、组织详细信息等)。我成功地修改了一些(具体的姓名、电话号码和电子邮件),但不是全部。
每当我尝试更新联系人的组织详细信息(Contacts.Organizations.COMPANY 和 Contacts.Organizations.TITLE)时,我的应用程序都会引发异常
java.lang.UnsupportedOperationException: Cannot update URL: content://contacts/people/69/organizations/69
代码片段如下:
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);