Search code examples
androidpreferenceringtone

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


Solution

  • 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