如何在运行时获取铃声偏好?

发布于 2024-10-17 00:44:35 字数 683 浏览 2 评论 0原文

我有以下 xml:

 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Ringtone preference" android:key="ringtone_option_preference">
    <RingtonePreference 
    android:key="ring_tone_pref"
    android:title="Set Ringtone Preference"
    android:showSilent="true"
    android:ringtoneType="notification"
    android:summary="Set Ringtone"/>
 </PreferenceScreen>

并且我希望每次通知即将显示时,查看铃声的值并相应地发出蜂鸣声:)...更准确地说,我的通知是在 BroadcastReceiver 类中生成的,并且每次接收器捕获到它创建新通知的内容...我只想根据首选项中设置的铃声更改通知的铃声..

我该怎么做?

谢谢迈克

i have the following xml:

 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Ringtone preference" android:key="ringtone_option_preference">
    <RingtonePreference 
    android:key="ring_tone_pref"
    android:title="Set Ringtone Preference"
    android:showSilent="true"
    android:ringtoneType="notification"
    android:summary="Set Ringtone"/>
 </PreferenceScreen>

And i want every time a notification is about to show, to look at the value of the ringtone and beep accordingly :)...To be more precise my notifications are generated in a broadcastReceiver class and each time the receiver catches something it creates a new notification...I just want the ringtone of the notification to change based on the ringtone set in the preferences..

How can I do that?

Thanks

Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷夜 2024-10-24 00:44:35

没关系,我找到了:

 SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context);
 String strRingtonePreference = preference.getString("ring_tone_pref", "DEFAULT_SOUND");        
 notification.sound = Uri.parse(strRingtonePreference);

Nevermind I found it:

 SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context);
 String strRingtonePreference = preference.getString("ring_tone_pref", "DEFAULT_SOUND");        
 notification.sound = Uri.parse(strRingtonePreference);
摇划花蜜的午后 2024-10-24 00:44:35
<RingtonePreference
            android:defaultValue="true"
            android:key="ringtone_sound"
            android:ringtoneType="notification"
            android:showSilent="true"
            android:showDefault="true"
            android:title="Sound"
            android:enabled="true" />

然后之后

String PREFERENCE_SOUND = "ringtone_sound";

private SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)

String strRingtonePreference = sharedPreferences.getString(PREFERENCE_SOUND, "DEFAULT_SOUND");
Uri defaultSoundUri = Uri.parse(strRingtonePreference);
notificationBuilder.setSound(defaultSoundUri);
<RingtonePreference
            android:defaultValue="true"
            android:key="ringtone_sound"
            android:ringtoneType="notification"
            android:showSilent="true"
            android:showDefault="true"
            android:title="Sound"
            android:enabled="true" />

Then After

String PREFERENCE_SOUND = "ringtone_sound";

private SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)

String strRingtonePreference = sharedPreferences.getString(PREFERENCE_SOUND, "DEFAULT_SOUND");
Uri defaultSoundUri = Uri.parse(strRingtonePreference);
notificationBuilder.setSound(defaultSoundUri);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文