开发者

How to get ringtone preference at runtime?

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开发者_C百科: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


Nevermind I found it:

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


<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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜