diff --git a/android/app/src/main/java/com/coboltforge/dontmind/multivnc/ui/VNCConnService.kt b/android/app/src/main/java/com/coboltforge/dontmind/multivnc/ui/VNCConnService.kt index 2421e2df..574c85ef 100644 --- a/android/app/src/main/java/com/coboltforge/dontmind/multivnc/ui/VNCConnService.kt +++ b/android/app/src/main/java/com/coboltforge/dontmind/multivnc/ui/VNCConnService.kt @@ -1,5 +1,6 @@ package com.coboltforge.dontmind.multivnc.ui +import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent @@ -114,13 +115,17 @@ class VNCConnService : Service() { val notificationIntent = Intent(this, VncCanvasActivity::class.java) val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0) - val notification = NotificationCompat.Builder(this, packageName) + val notificationBuilder = NotificationCompat.Builder(this, packageName) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.connected_to, hosts)) .setContentIntent(pendingIntent) .setOnlyAlertOnce(true) - .build() + if (Build.VERSION.SDK_INT >= 31) { + notificationBuilder.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_IMMEDIATE + } + val notification = notificationBuilder.build() + startForeground(NOTIFICATION_ID, notification) } // stay until explicitly stopped