以编程方式更新 android 联系人中的组织名称
Updating organization name in android contacts programmatically
我正在尝试更新单个联系人中的组织名称,但它对我不起作用,我正在使用以下代码
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY,company)
.build());
请帮助我,在此先感谢。
String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] orgWhereParams = new String[]{String.valueOf(id),
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
operationList
.add(ContentProviderOperation
.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(orgWhere, orgWhereParams)
.withValue(
ContactsContract.CommonDataKinds.Organization.DATA,
guCon.getCompany()).build());
你写的没有提到你想更新哪个联系人。
一个Contact
是由一个或多个RawContacts
构建的,您需要将要更新的ContentProviderOperation
和RawContact._ID
传递给
每个 RawContact
都是由多个 Data
条目之一构建的,如果您有特定的 Data._ID
要更新,那就更好了。
假设您只有 RawContact._ID
,并且它是 rawContactId
,那么应该更新它:
String selection = Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?";
String[] selectionArgs = new String[] { rawContactId, CommonDataKinds.Organization.CONTENT_ITEM_TYPE };
opt.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
.withSelection(selection, selectionArgs)
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, company)
.build());
这告诉数据库更新属于 rawContactId
且类型为 Organization
的数据行
我正在尝试更新单个联系人中的组织名称,但它对我不起作用,我正在使用以下代码
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY,company)
.build());
请帮助我,在此先感谢。
String orgWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] orgWhereParams = new String[]{String.valueOf(id),
ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE};
operationList
.add(ContentProviderOperation
.newUpdate(ContactsContract.Data.CONTENT_URI)
.withSelection(orgWhere, orgWhereParams)
.withValue(
ContactsContract.CommonDataKinds.Organization.DATA,
guCon.getCompany()).build());
你写的没有提到你想更新哪个联系人。
一个Contact
是由一个或多个RawContacts
构建的,您需要将要更新的ContentProviderOperation
和RawContact._ID
传递给
每个 RawContact
都是由多个 Data
条目之一构建的,如果您有特定的 Data._ID
要更新,那就更好了。
假设您只有 RawContact._ID
,并且它是 rawContactId
,那么应该更新它:
String selection = Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?";
String[] selectionArgs = new String[] { rawContactId, CommonDataKinds.Organization.CONTENT_ITEM_TYPE };
opt.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
.withSelection(selection, selectionArgs)
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, company)
.build());
这告诉数据库更新属于 rawContactId
且类型为 Organization