Skip to content

Commit

Permalink
[Android] Fix crashlytics issue with service on Android 12+ (#163)
Browse files Browse the repository at this point in the history
* [Android] Fix crashlytics issue with service on Android 12+

* [Android] Update pending intent flag for Android 12+ AlarmReceiver

* [Android] Send pending intent in AlarmReceiver
  • Loading branch information
CoThomas authored Mar 14, 2024
1 parent 825970c commit ad9260b
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gdelataillade.alarm.alarm

import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
Expand All @@ -11,7 +12,10 @@ class AlarmReceiver : BroadcastReceiver() {
val serviceIntent = Intent(context, AlarmService::class.java)
serviceIntent.putExtras(intent)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val pendingIntent = PendingIntent.getForegroundService(context, 1, serviceIntent, PendingIntent.FLAG_IMMUTABLE)
pendingIntent.send()
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(serviceIntent)
} else {
context.startService(serviceIntent)
Expand Down

0 comments on commit ad9260b

Please sign in to comment.