Skip to content

Commit

Permalink
Add native android alarm service backward compatibility with older mo…
Browse files Browse the repository at this point in the history
…del versions
  • Loading branch information
gdelataillade committed Oct 7, 2024
1 parent 4e43417 commit 34df128
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class AlarmService : Service() {
val id = intent.getIntExtra("id", 0)
val action = intent.getStringExtra(AlarmReceiver.EXTRA_ALARM_ACTION)

Log.d("AlarmService", "ringing alarms: $ringingAlarmIds")
if (ringingAlarmIds.isNotEmpty()) {
Log.d("AlarmService", "An alarm is already ringing. Ignoring new alarm with id: $id")
unsaveAlarm(id)
Expand All @@ -68,12 +67,18 @@ class AlarmService : Service() {
val fullScreenIntent = intent.getBooleanExtra("fullScreenIntent", true)

val notificationSettingsJson = intent.getStringExtra("notificationSettings")
val jsonObject = JSONObject(notificationSettingsJson)
val map: MutableMap<String, Any> = mutableMapOf()
jsonObject.keys().forEach { key ->
map[key] = jsonObject.get(key)
val notificationSettings = if (notificationSettingsJson != null) {
val jsonObject = JSONObject(notificationSettingsJson)
val map: MutableMap<String, Any> = mutableMapOf()
jsonObject.keys().forEach { key ->
map[key] = jsonObject.get(key)
}
NotificationSettings.fromJson(map)
} else {
val notificationTitle = intent.getStringExtra("notificationTitle") ?: "Title"
val notificationBody = intent.getStringExtra("notificationBody") ?: "Body"
NotificationSettings(notificationTitle, notificationBody)
}
val notificationSettings = NotificationSettings.fromJson(map)

// Handling notification
val notificationHandler = NotificationHandler(this)
Expand Down

0 comments on commit 34df128

Please sign in to comment.