简体   繁体   English

首选项铃声默认值

[英]Preference ringtone default value

I have this in my preferences.xml 我在偏好.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 每当我第一次开始全新安装应用程序时,默认值为静音:(当我点击铃声首选项时,对话框打开时默认选择静音。我希望默认选择“默认铃声”。我怎样才能做到这一点 在此输入图像描述

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 ... 如何将默认值设置为“默认铃声”而不是静音,我不知道为什么这个默认为我的默认我不设置在我的代码中的任何地方,默认是来自android系统的默认值...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM