mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2025-12-23 09:24:23 +01:00
Fix crash.
Disable ringtone if not available. Information on UI will be displayed about the alarm. Attempt to invoke virtual method 'void android.media.Ringtone.setVolume(float)' on a null object reference
This commit is contained in:
@@ -12,17 +12,21 @@ internal class AlarmHandler @Inject constructor(
|
|||||||
private val context: Context
|
private val context: Context
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private val highLevelRingtone = RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).apply {
|
private val highLevelRingtone = RingtoneManager
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
|
||||||
volume = 1f
|
?.apply {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
volume = 1f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private val mediumLevelRingtone = RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE)).apply {
|
private val mediumLevelRingtone = RingtoneManager
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE))
|
||||||
volume = 0.5f
|
?.apply {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
volume = 0.5f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun playAlarm(alarmLevel: AlarmLevel) {
|
fun playAlarm(alarmLevel: AlarmLevel) {
|
||||||
val ringtone = when (alarmLevel) {
|
val ringtone = when (alarmLevel) {
|
||||||
@@ -34,7 +38,7 @@ internal class AlarmHandler @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun pauseAlarm() {
|
fun pauseAlarm() {
|
||||||
highLevelRingtone.takeIf { it.isPlaying }?.stop()
|
highLevelRingtone?.takeIf { it.isPlaying }?.stop()
|
||||||
mediumLevelRingtone.takeIf { it.isPlaying }?.stop()
|
mediumLevelRingtone?.takeIf { it.isPlaying }?.stop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user