我用一個簡單的選擇對話框讓用戶選擇一個通知聲音,這裏的代碼開始選擇器:RingtoneManager顯示手機鈴聲,而不是通知聲音
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION | RingtoneManager.TYPE_ALARM);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.selectSound));
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, Uri.parse(LocalCfg.getNotificationSound()));
startActivityForResult(intent, SELECT_RINGTONE_REQUEST);
的LocalCfg.getNotificationSound()
簡單地檢查內部SharedPreferences
設置,在情況下返回默認通知聲音Uri
設置尚不存在:在所有測試的手機觀察
public static String getNotificationSound() {
return mPrefs.getString(KEY_PREF_NOTIFY_SOUND_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString());
}
問題:「去故障「列出的聲音不是通知/報警聲音,而是實際的電話鈴聲(系統默認或由用戶設置的自定義)。
某些手機(Samsung Galaxy Young,Xperia Z1 Compact)顯示爲「默認通知音」(實際上是錯誤的),其他一些手機(Nexus設備,SDK 22)顯示爲「默認鈴聲」。
爲什麼會發生如果我明確通過RingtoneManager.TYPE_NOTIFICATION | RingtoneManager.TYPE_ALARM
標誌?