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,13 +12,17 @@ internal class AlarmHandler @Inject constructor(
|
||||
private val context: Context
|
||||
) {
|
||||
|
||||
private val highLevelRingtone = RingtoneManager.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)).apply {
|
||||
private val highLevelRingtone = RingtoneManager
|
||||
.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM))
|
||||
?.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
|
||||
.getRingtone(context, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE))
|
||||
?.apply {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
volume = 0.5f
|
||||
}
|
||||
@@ -34,7 +38,7 @@ internal class AlarmHandler @Inject constructor(
|
||||
}
|
||||
|
||||
fun pauseAlarm() {
|
||||
highLevelRingtone.takeIf { it.isPlaying }?.stop()
|
||||
mediumLevelRingtone.takeIf { it.isPlaying }?.stop()
|
||||
highLevelRingtone?.takeIf { it.isPlaying }?.stop()
|
||||
mediumLevelRingtone?.takeIf { it.isPlaying }?.stop()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user