Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #634: set foreground service behavior on API 31+ #648

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.app.Notification
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.IBinder
import android.os.PowerManager
import androidx.core.app.NotificationCompat
Expand Down Expand Up @@ -167,7 +167,7 @@ class UploadService : Service() {
}

private fun stopServiceForeground() {
if (Build.VERSION.SDK_INT >= 24) {
if (SDK_INT >= 24) {
stopForeground(STOP_FOREGROUND_REMOVE)
} else {
@Suppress("DEPRECATION")
Expand Down Expand Up @@ -213,11 +213,16 @@ class UploadService : Service() {
"Starting UploadService. Debug info: $UploadServiceConfig"
}

val notification = NotificationCompat.Builder(this, UploadServiceConfig.defaultNotificationChannel!!)
val builder = NotificationCompat.Builder(this, UploadServiceConfig.defaultNotificationChannel!!)
.setSmallIcon(android.R.drawable.ic_menu_upload)
.setOngoing(true)
.setGroup(UploadServiceConfig.namespace)
.build()

if (SDK_INT >= 31) {
builder.foregroundServiceBehavior = Notification.FOREGROUND_SERVICE_IMMEDIATE
}

val notification = builder.build()

startForeground(UPLOAD_NOTIFICATION_BASE_ID, notification)

Expand Down
Loading