diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index dd9a78b..c969055 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -6,6 +6,7 @@ + + android:exported="false" + android:foregroundServiceType="specialUse"> + + diff --git a/android/app/src/main/java/com/massive/TimerService.kt b/android/app/src/main/java/com/massive/TimerService.kt index 86b6ff5..68ae043 100644 --- a/android/app/src/main/java/com/massive/TimerService.kt +++ b/android/app/src/main/java/com/massive/TimerService.kt @@ -9,6 +9,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager +import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE import android.media.AudioAttributes import android.media.MediaPlayer import android.net.Uri @@ -76,7 +77,14 @@ class TimerService : Service() { secondsLeft = (intent?.getIntExtra("milliseconds", 0) ?: 0) / 1000 currentDescription = intent?.getStringExtra("description").toString() secondsTotal = secondsLeft - startForeground(ONGOING_ID, getProgress(secondsLeft).build()) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + startForeground(ONGOING_ID, getProgress(secondsLeft).build(), FOREGROUND_SERVICE_TYPE_SPECIAL_USE) + } else + { + startForeground(ONGOING_ID, getProgress(secondsLeft).build()) + } + battery() Log.d("TimerService", "onStartCommand seconds=$secondsLeft")