5

我的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" />

每次我第一次开始全新安装应用程序时,默认值为静音:(,当我点击铃声首选项时,对话框打开时默认选择静音。我希望默认选择“默认铃声”。我怎样才能做到这一点 在此处输入图像描述

我怎样才能将默认值设置为“默认铃声”而不是静音,我不知道为什么这是我的默认值我没有在我的代码中的任何地方设置,静音是android系统的默认值......

4

3 回答 3

7

将默认值设置为默认铃声的最简单方法

<RingtonePreference
        android:showDefault="true"
        android:showSilent="true"
        android:defaultValue="content://settings/system/notification_sound"
                    .......
        >
</RingtonePreference>
于 2012-12-25T08:36:47.943 回答
6

我正在搜索如何为铃声设置默认值,并意识到当未设置首选项时,该值为空并且默认选择静音。但我这样做

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();
}

我希望这对其他人有帮助。顺便说一句,我吓坏了找到这个解决方法,而且我已经好几个小时了

于 2011-10-04T08:47:22.453 回答
1

只需禁用“静音”项目:

<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">
于 2011-12-01T22:10:03.300 回答