我正在尝试为 Android 构建自定义类型的闹钟,并且我已经设置了一个设置页面以允许用户选择他们想要使用的闹钟声音。在他们选择它之后,它会被放入 SharedPreferences 中,这很容易。
我遇到的问题是如何在使用 RingtoneManager.TYPE_ALARM 时播放他们选择的警报,以便音量基于系统警报声音而不是系统通知音量。
我已经尝试了多种方法来让它使用警报音量,但似乎没有任何效果。
1.
Uri currentRingtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
currentRingtone = RingtoneManager.getRingtone(context, currentRingtoneUri);
currentRingtone.play();
2.
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String syncConnPref = sharedPref.getString("alarm_new_alarm_sound", null);
if (syncConnPref != null) {
RingtoneManager.getRingtone(this, Uri.parse(syncConnPref)).play();
}
我似乎找不到任何其他直接播放实际警报音量的方法。网上的一切都只是在播放铃声。
如果有人对使用警报音量有任何见解,我将不胜感激。