Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preference ringtone default value

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 ...

like image 351
Lukap Avatar asked Oct 03 '11 12:10

Lukap


3 Answers

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>
like image 163
Pawan Maheshwari Avatar answered Nov 05 '22 15:11

Pawan Maheshwari


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

like image 30
Lukap Avatar answered Nov 05 '22 14:11

Lukap


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">
like image 22
Nikoi Avatar answered Nov 05 '22 14:11

Nikoi