3

i have a ringtone preference. How can i get the selection? I have the following kind-of-code:

if(preferences.getString("ringtonePref", "n/a") != ??)
            {
                Toast.makeText(TutorialPref.this,   "Chosen ringtone: silent", Toast.LENGTH_LONG).show();
            }
            else if(preferences.getString("ringtonePref", "n/a") != "DEFAULT_RINGTONE_URI" )
            {
                Toast.makeText(TutorialPref.this,   "Chosen ringtone: + default", Toast.LENGTH_LONG).show();
            }
erdomester
  • 11,789
  • 32
  • 132
  • 234

1 Answers1

4

This is how you assign the selection to your notification instance.

String strRingtonePreference = preferences.getString("ringtonePref", "DEFAULT_RINGTONE_URI");
notification.sound = Uri.parse(strRingtonePreference);

Where notification is :

Notification notification = new Notification(icon, tickerText, time);

You will find more info here : http://developer.android.com/reference/android/app/Notification.html

Radu
  • 56
  • 2
  • `"DEFAULT_RINGTONE_URI"` doesn't work. Rather pass `null` as that argument, and call `RingtoneManager.getActualDefaultRingtoneUri` instead of `Uri.parse` if `SharedPreferences.getString` returns `null`. –  Nov 05 '13 at 12:29
  • `Settings.System.DEFAULT_NOTIFICATION_URI` is a good default as well when the preference returns null. – Jeshurun Nov 11 '13 at 15:04