开发者

Preference ringtone default value

开发者 https://www.devze.com 2023-04-10 21:09 出处:网络
I have this in my preferences.xml 开发者_开发问答<RingtonePreference android:key=\"ringtone_uri\"

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

Preference ringtone default value

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


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>


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号