【发布时间】:2014-07-27 03:01:54
【问题描述】:
我正在使用preferences.xml 来允许选择铃声(以及其他首选项)。这是代码
<RingtonePreference
android:key="shuttle_tone"
android:ringtoneType="notification"
android:showDefault="false"
android:showSilent="true"
android:defaultValue="content://settings/system/notification_sound"
android:summary="Select the tone that signals the start of the next shuttle"
android:title="Shuttle Tone" />
...一堆其他偏好
Preferences 活动在基本 UI 中启动
case R.id.btn_settings:
Intent settingsActivity = new Intent(getBaseContext(), PreferenceSelect.class);
startActivity(settingsActivity);
铃声,app的主要功能启动时,在此取回
case R.id.run_start:
// Retrieve the shuttle & level notifications
SharedPreferences preference = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
String strRingtonePreference = preference.getString(
"shuttle_tone", "DEFAULT_SOUND");
shuttle_rt = RingtoneManager.getRingtone(
getApplicationContext(),
Uri.parse(strRingtonePreference));
/* More stuff ... during which the ringtone is played periodically */
问题是:当程序首次安装时,如果用户在没有访问首选项屏幕的情况下启动 run_start 代码,则没有声音。
但是,这是奇怪的部分,如果用户启动 btn_settings(首选项屏幕),则选择 android:defaultValue,即使用户实际上并未启动铃声选择。换句话说,用户只需访问首选项屏幕即可选择默认值。如果用户不这样做,它就会保持沉默。
我错过了什么?
【问题讨论】:
标签: android sharedpreferences default-value