Skip to content

Commit

Permalink
Android: VNCConnService: maybe workaround ForegroundServiceStartNotAl…
Browse files Browse the repository at this point in the history
  • Loading branch information
bk138 committed Aug 30, 2023
1 parent 359e583 commit 93c12c7
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 93c12c7

Please sign in to comment.