Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...