Lukap
Lukap

Reputation: 31963

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

Upvotes: 5

Views: 5157

Answers (3)

Pawan Maheshwari
Pawan Maheshwari

Reputation: 15366

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>

Upvotes: 7

Lukap
Lukap

Reputation: 31963

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

Upvotes: 6

Nikoi
Nikoi

Reputation: 389

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

Upvotes: 1

Related Questions