views:

465

answers:

1

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

I have found a way to set the default ringtone that applies to all contacts without an individual ringtone. But that is not what i'm trying to accomplish.

I want the application to have a button "Apply ringtone to contact". When i click, I start 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. Now all the app needs to do is to apply the selected ringtone to that spesific contact.

The code for displaying and selecting contacts by an activity is already implemented and seems to work on with the app. Its only the last part left, and I have no clue about how to solve this.

Any help would be usefull.

+3  A: 

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).

Mef
Thanks, That was a very helpful discussion. Lot's of frustrated developers about the lack of documentation and examples from Google. I'll give your pasted code a try. Hopefully to work on 1.5 -> 2.1 ... At the moment the current code the app is using only works for 1.5 and 1.6, not for 2.0 or 2.1... E.g it works for Magic, Hero and G1, but not for DROID or Nexus
PHP_Jedi