mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-05-15 18:26:48 -04:00
refactor: update startForeground() with explicit service type
from Android Q (API level 29) foreground services require an explicit service type to be specified.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user