From 07c847ea68371371a536344b39546e9d264271bd Mon Sep 17 00:00:00 2001 From: andrekir Date: Sun, 18 Jun 2023 17:33:06 -0300 Subject: [PATCH] refactor: update startForeground() with explicit service type from Android Q (API level 29) foreground services require an explicit service type to be specified. --- .../java/com/geeksville/mesh/service/MeshService.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 3c977a999..e82f78083 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -3,6 +3,7 @@ package com.geeksville.mesh.service import android.app.Service import android.content.Context import android.content.Intent +import android.content.pm.ServiceInfo import android.os.IBinder import android.os.RemoteException import androidx.core.app.ServiceCompat @@ -270,7 +271,15 @@ class MeshService : Service(), Logging { // but if we don't really need foreground we immediately stop it. val notification = serviceNotifications.createServiceStateNotification(notificationSummary) - startForeground(serviceNotifications.notifyId, notification) + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + startForeground( + serviceNotifications.notifyId, + notification, + ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST + ) + } else { + startForeground(serviceNotifications.notifyId, notification) + } return if (!wantForeground) { ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE) START_NOT_STICKY