mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00: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:
parent
38332b346e
commit
6abe0124d2
1 changed files with 7 additions and 12 deletions
|
|
@ -104,6 +104,7 @@ import org.meshtastic.core.model.util.toPIIString
|
||||||
import org.meshtastic.core.prefs.mesh.MeshPrefs
|
import org.meshtastic.core.prefs.mesh.MeshPrefs
|
||||||
import org.meshtastic.core.prefs.ui.UiPrefs
|
import org.meshtastic.core.prefs.ui.UiPrefs
|
||||||
import org.meshtastic.core.strings.R
|
import org.meshtastic.core.strings.R
|
||||||
|
import timber.log.Timber
|
||||||
import java.util.Random
|
import java.util.Random
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
@ -389,25 +390,19 @@ class MeshService :
|
||||||
this,
|
this,
|
||||||
MeshServiceNotifications.SERVICE_NOTIFY_ID,
|
MeshServiceNotifications.SERVICE_NOTIFY_ID,
|
||||||
notification,
|
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()) {
|
if (hasLocationPermission()) {
|
||||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_MANIFEST
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE or
|
||||||
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION
|
||||||
} else {
|
} else {
|
||||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
0
|
0 // No specific type needed for older Android versions
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} catch (ex: SecurityException) {
|
} catch (ex: Exception) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
Timber.e(ex, "Error starting foreground service")
|
||||||
errormsg(
|
|
||||||
"startForeground failed, likely due to missing POST_NOTIFICATIONS permission on Android 13+",
|
|
||||||
ex,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
errormsg("startForeground failed", ex)
|
|
||||||
}
|
|
||||||
return START_NOT_STICKY
|
return START_NOT_STICKY
|
||||||
}
|
}
|
||||||
return if (!wantForeground) {
|
return if (!wantForeground) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue