How to get ringtone preference at runtime?
Asked Answered
N

2

5

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

Nonalignment answered 12/2, 2011 at 11:45 Comment(0)
N
24

Nevermind I found it:

 SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context);
 String strRingtonePreference = preference.getString("ring_tone_pref", "DEFAULT_SOUND");        
 notification.sound = Uri.parse(strRingtonePreference);
Nonalignment answered 12/2, 2011 at 12:31 Comment(2)
did you used OnPrefrenceChangeListener() in the PreferenceFragment?Perlman
@mixkat. how can i set ring tone name as a summery of RingTonePreference?Bissau
P
4
<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);
Perlman answered 17/5, 2016 at 13:30 Comment(1)
how can i set ring tone name as a summery of RingTonePreference?Bissau

© 2022 - 2024 — McMap. All rights reserved.