mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-12 19:07:28 -04:00
fix(service): Update foreground service type and error handling (#3246)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
@@ -104,6 +104,7 @@ import org.meshtastic.core.model.util.toPIIString
|
||||
import org.meshtastic.core.prefs.mesh.MeshPrefs
|
||||
import org.meshtastic.core.prefs.ui.UiPrefs
|
||||
import org.meshtastic.core.strings.R
|
||||
import timber.log.Timber
|
||||
import java.util.Random
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -389,25 +390,19 @@ class MeshService :
|
||||
this,
|
||||
MeshServiceNotifications.SERVICE_NOTIFY_ID,
|
||||
notification,
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
if (hasLocationPermission()) {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE or
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION
|
||||
} else {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
|
||||
}
|
||||
} else {
|
||||
0
|
||||
0 // No specific type needed for older Android versions
|
||||
},
|
||||
)
|
||||
} catch (ex: SecurityException) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
errormsg(
|
||||
"startForeground failed, likely due to missing POST_NOTIFICATIONS permission on Android 13+",
|
||||
ex,
|
||||
)
|
||||
} else {
|
||||
errormsg("startForeground failed", ex)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
Timber.e(ex, "Error starting foreground service")
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
return if (!wantForeground) {
|
||||
|
||||
Reference in New Issue
Block a user