Vidar Vestnes Vidar Vestnes - 6 days ago 7
Android Question

How can I set a ringtone for an individual contact on Android?

How can I apply a ringtone to only the selected contact?

I have found a way to set the default ringtone that applies to all contacts, but that is not my goal.

I want an application to have a button ("Apply ringtone to contact") that, when clicked, starts an

activityForResult
displaying a list of all contacts on the phone. When a contact is selected, the contact activity closes and returns with a URI to the contact. Then the app needs to apply the selected ringtone to that specific contact.

The code for displaying and selecting contacts by an activity is already implemented and seems to work on the app.

Leo Leo
Answer

You can use ContactsContract.Contacts which has a column CUSTOM_RINGTONE (which is a read/write column!) for this purpose.

Uri contactUri;
ContentValues values = new ContentValues();
values.put(ContactsContract.Contacts.CUSTOM_RINGTONE, 
    newRingtoneUri.toString());
context.getContentResolver().update(contactUri, values, where, args);

Furthermore, you may find this discussion useful (code taken from there).