Skip to content

Commit

Permalink
fix: Specify foreground service type for workers
Browse files Browse the repository at this point in the history
Change-Id: I88c12e61590c6ca55e8a06213150df8039c4dfb4
  • Loading branch information
XayahSuSuSu committed Nov 17, 2024
1 parent 0e5ab6b commit 68429f7
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
import android.net.Uri
import android.os.Build
import android.provider.Settings
Expand Down Expand Up @@ -117,7 +118,11 @@ object NotificationUtil {
): ForegroundInfo {
createChannelIfNecessary(context)
val notification = builder.setContentTitle(title).setContentText(content).setProgress(max, progress, indeterminate).setOngoing(ongoing)
return ForegroundInfo(progressNotificationId, notification.build())
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(progressNotificationId, notification.build(), FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
} else {
ForegroundInfo(progressNotificationId, notification.build())
}
}

fun createForegroundInfo(
Expand All @@ -129,6 +134,10 @@ object NotificationUtil {
): ForegroundInfo {
createChannelIfNecessary(context)
val notification = builder.setContentTitle(title).setContentText(content).setOngoing(ongoing)
return ForegroundInfo(progressNotificationId, notification.build())
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
ForegroundInfo(progressNotificationId, notification.build(), FOREGROUND_SERVICE_TYPE_SPECIAL_USE)
} else {
ForegroundInfo(progressNotificationId, notification.build())
}
}
}

0 comments on commit 68429f7

Please sign in to comment.