I resolved this problem.It was my mistake.I was using Data.CONTACT_ID value to insert the data to, but it must be the Data.RAW_CONTACT_ID value.On the devices that my program worked was because the two fields had equal values. The Data.Contact_ID is used to be updated or deleted information from the chosen contact. It is documented in http://developer.android.com/reference/android/provider/ContactsContract.Data.html.
Adding field programatically to contact in android devices not working on android 4.3
-
02-10-2022 - |
Question
I am developing an android app that adds fields to some contact that is in the android's data base. Through the app I can delete fields, too. I tested the application on some devices and the fields I add or delete with the application are added/deleted from the contact's information and from the device's database. But when I tested it on android 4.3 (Samsung Galaxy S4) it is not working(only for the adding, deleting and updating fields works). I add field in that way :
ContentValues values = new ContentValues();
values.put(Data.RAW_CONTACT_ID, contactId);
values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
values.put(Phone.NUMBER, "12-45-4-33");
values.put(Phone.LABEL, "assistance");
Uri dataUri = getContentResolver().insert(Data.CONTENT_URI,values);
I even tryed to add field with ContentProviderOperation in that way:
ArrayList<ContentProviderOperation> values =
new ArrayList<ContentProviderOperation>();
values.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
.withValue(Data.RAW_CONTACT_ID, contactId)
.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
.withValue(Phone.NUMBER, "12-45-4-33")
.withValue(Phone.LABEL, "assistance")
.build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY, values);
Thank you.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow