catch exceptions thrown at getting the default alarm title
This commit is contained in:
parent
5b30c9a63d
commit
aa8dcf0801
1 changed files with 8 additions and 2 deletions
|
@ -461,8 +461,14 @@ fun Context.getFormattedSeconds(seconds: Int, showBefore: Boolean = true) = when
|
|||
|
||||
fun Context.getDefaultAlarmUri(type: Int) = RingtoneManager.getDefaultUri(if (type == ALARM_SOUND_TYPE_NOTIFICATION) RingtoneManager.TYPE_NOTIFICATION else RingtoneManager.TYPE_ALARM)
|
||||
|
||||
fun Context.getDefaultAlarmTitle(type: Int) = RingtoneManager.getRingtone(this, getDefaultAlarmUri(type))?.getTitle(this)
|
||||
?: getString(R.string.alarm)
|
||||
fun Context.getDefaultAlarmTitle(type: Int): String {
|
||||
val alarmString = getString(R.string.alarm)
|
||||
return try {
|
||||
RingtoneManager.getRingtone(this, getDefaultAlarmUri(type))?.getTitle(this) ?: alarmString
|
||||
} catch (e: Exception) {
|
||||
alarmString
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getDefaultAlarmSound(type: Int) = AlarmSound(0, getDefaultAlarmTitle(type), getDefaultAlarmUri(type).toString())
|
||||
|
||||
|
|
Loading…
Reference in a new issue