Preference ringtone default value
Asked Answered
L

3

5

I have this in my preferences.xml

        <RingtonePreference android:key="ringtone_uri"
            android:title="@string/preferences_select_ringtone"
            android:showDefault="true" android:srinlent="true"
            android:summary="@string/preferences_select_ringtone_summary" />

And every time when I first start fresh install of an app, the default value in silent :(, When I tap on the ringtone preference the dialog is opened with silent selected as default. I want by default "Default ringtone" to be selected. How can I do this enter image description here

How can I set the default value to be "default ringtone" not silent, I do not know why is this silent as my default I do not set in any place in my code, the silent is the default from android system ...

Larios answered 3/10, 2011 at 12:3 Comment(0)
L
6

I was searching how to set default value for the ringtone, and realized that when the preference is not set than the value is empty and the silent is selected as default. But I do this

defaultstr = Uri.parse(PreferenceManager.getDefaultSharedPreferences(context).getString("r_uri",
    android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()));
//than I do this, I save the default ringtone to my setting
 if (defaultstr.equals(android.provider.Settings.System.DEFAULT_RINGTONE_URI)) {
    PreferenceManager.getDefaultSharedPreferences(context).edit().putString("r_uri",
        android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()).commit();
}

I hope this will help to someone else. btw I freak out finding this workaround, and I was starching my head for hours

Larios answered 4/10, 2011 at 8:47 Comment(0)
D
7

The easiest way to set default value to default ringtone

<RingtonePreference
        android:showDefault="true"
        android:showSilent="true"
        android:defaultValue="content://settings/system/notification_sound"
                    .......
        >
</RingtonePreference>
Diffluent answered 25/12, 2012 at 8:36 Comment(0)
L
6

I was searching how to set default value for the ringtone, and realized that when the preference is not set than the value is empty and the silent is selected as default. But I do this

defaultstr = Uri.parse(PreferenceManager.getDefaultSharedPreferences(context).getString("r_uri",
    android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()));
//than I do this, I save the default ringtone to my setting
 if (defaultstr.equals(android.provider.Settings.System.DEFAULT_RINGTONE_URI)) {
    PreferenceManager.getDefaultSharedPreferences(context).edit().putString("r_uri",
        android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString()).commit();
}

I hope this will help to someone else. btw I freak out finding this workaround, and I was starching my head for hours

Larios answered 4/10, 2011 at 8:47 Comment(0)
V
1

Just disable the "Silent" item :

<RingtonePreference android:key="ringtone_uri"
            android:title="@string/preferences_select_ringtone"
            android:showDefault="true" android:srinlent="true"
            android:summary="@string/preferences_select_ringtone_summary" 
            android:showSilent="false">
Verticillate answered 1/12, 2011 at 22:10 Comment(1)
This may work, but only as long as you don't want to offer your users to select a silent ringtone.Lussi

© 2022 - 2024 — McMap. All rights reserved.