2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-21 17:37:39 +00:00

Ignore ForegroundServiceStartNotAllowedException

This commit is contained in:
Albert Vaca Cintora 2025-05-05 22:02:05 +02:00
parent dbbce2aee1
commit feae6b54a9
No known key found for this signature in database

View File

@ -234,7 +234,12 @@ class BackgroundService : Service() {
Log.d(LOG_TAG, "onStartCommand")
if (NotificationHelper.isPersistentNotificationEnabled(this)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(FOREGROUND_NOTIFICATION_ID, createForegroundNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE)
try {
startForeground(FOREGROUND_NOTIFICATION_ID, createForegroundNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE)
} catch (e: IllegalStateException) { // To catch ForegroundServiceStartNotAllowedException
Log.w("BackgroundService", "Couldn't startForeground", e);
return START_STICKY
}
}
else {
startForeground(FOREGROUND_NOTIFICATION_ID, createForegroundNotification())