Reputation: 701
I have a list of contacts with custom ringtones and I need to reset the ringtones of specific contacts back to default.
As mentioned here, when setting CUSTOM_RINGTONE URI: "If null or missing, the default ringtone is used." Since "put" wouldn't accept null, i passed empty string ("") as shown in the code below, it runs and seems to be OK (if I go to that contact, it shows "default" on the Ringtones field).
However when that contact calls, the phone app crash!
(If I go to that contact and manually set default, again - no crash...)
How to set the ringtones field to "null or missing" ?
private void ResetContactRingTone(String idOfContact) {
try {
Uri contactData = ContactsContract.Contacts.CONTENT_URI;
String contactId = contactData.getLastPathSegment();
Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, idOfContact);
ContentValues localContentValues = new ContentValues();
localContentValues.put(ContactsContract.Data.RAW_CONTACT_ID, contactId);
localContentValues.put(ContactsContract.Data.CUSTOM_RINGTONE, ""); // <<----ho to set here "null or missing"?
getContentResolver().update(localUri, localContentValues, null, null);
}catch (Exception ex) {
Log.e(TAG, "ResetContactRingTone failed, Excpetion: " + ex.getMessage());
}
}
Upvotes: 0
Views: 702
Reputation: 701
Found the solution:
replace this
localContentValues.put(ContactsContract.Data.CUSTOM_RINGTONE, "");
with this
localContentValues.putNull(ContactsContract.Data.CUSTOM_RINGTONE);
and it works!
Upvotes: 4