mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00: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:
parent
744ff2054d
commit
07c847ea68
1 changed files with 10 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue