问题描述
如何将铃声仅应用到选定的联系人?
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.
我希望应用程序具有一个按钮(将铃声应用于联系人),单击该按钮会启动 activityForResult
显示电话上所有联系人的列表。选择联系人后,联系人活动将关闭并返回URI到该联系人。然后,应用程序需要将选定的铃声应用于该特定联系人。
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.
推荐答案
您可以使用具有用于此目的的列 CUSTOM_RINGTONE
(这是读/写列!)。
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).
这篇关于如何在Android上为单个联系人设置铃声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!