Reputation: 2757
I am trying to update the organization name in a single contact but it is not worked for me, I am using following code
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());
Please help me, Thanks in advance.
Upvotes: 0
Views: 510
Reputation: 28179
What you wrote doesn't mention which contact you want to update.
A Contact
is built from one or more RawContacts
, you need to pass the ContentProviderOperation
the RawContact._ID
that you want to update.
Each RawContact
is built from one of more Data
entries, if you have the specific Data._ID
you want to update, that'll be even better.
Assuming you only have the RawContact._ID
, and it's rawContactId
, then this should update it:
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());
This tells the DB to update the data row(s) that belong to rawContactId
, and are of type Organization
Upvotes: 1
Reputation: 2295
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());
Upvotes: 0