From ed3bf50bc5e675bd531c0cfd415a10dd2ad0fece Mon Sep 17 00:00:00 2001 From: Thomas COQUAN Date: Tue, 12 Mar 2024 17:07:34 +0100 Subject: [PATCH] [Android] Fix crashlytics issue with service on Android 12+ --- android/build.gradle | 5 ----- .../gdelataillade/alarm/alarm/AlarmReceiver.kt | 6 ++---- .../gdelataillade/alarm/alarm/AlarmWorker.kt | 17 ----------------- 3 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmWorker.kt diff --git a/android/build.gradle b/android/build.gradle index d673ce51..4f0e71be 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -45,9 +45,4 @@ android { defaultConfig { minSdkVersion 19 } -} - -dependencies { - implementation 'androidx.work:work-runtime:2.7.1' - implementation 'com.google.guava:guava:27.0.1-android' } \ No newline at end of file diff --git a/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmReceiver.kt b/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmReceiver.kt index ed03c7c3..b6642405 100644 --- a/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmReceiver.kt +++ b/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmReceiver.kt @@ -1,11 +1,10 @@ package com.gdelataillade.alarm.alarm +import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.os.Build -import androidx.work.OneTimeWorkRequest -import androidx.work.WorkManager import io.flutter.Log class AlarmReceiver : BroadcastReceiver() { @@ -14,8 +13,7 @@ class AlarmReceiver : BroadcastReceiver() { serviceIntent.putExtras(intent) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - val request = OneTimeWorkRequest.Builder(AlarmWorker::class.java).addTag(AlarmWorker.TAG).build() - WorkManager.getInstance(context).enqueue(request) + PendingIntent.getForegroundService(context, 1, serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT) } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { context.startForegroundService(serviceIntent) } else { diff --git a/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmWorker.kt b/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmWorker.kt deleted file mode 100644 index a722fd74..00000000 --- a/android/src/main/kotlin/com/gdelataillade/alarm/alarm/AlarmWorker.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.gdelataillade.alarm.alarm - -import android.content.Context -import androidx.work.Worker -import androidx.work.WorkerParameters - - -class AlarmWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { - companion object { - const val TAG = "AlarmWorker" - } - - override fun doWork(): Result { - //call methods to perform background task - return Result.success() - } -}