Commit 608fb08e authored by wanglei's avatar wanglei

...

parent a28d928c
......@@ -8,6 +8,7 @@ import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.ServiceInfo
import android.graphics.BitmapFactory
import android.graphics.drawable.Icon
import android.os.Build
......@@ -37,7 +38,7 @@ class StayNotificationService : Service() {
fun Context.startStayNotification() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
return
}
val intent = Intent(this, StayNotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
......@@ -51,13 +52,17 @@ class StayNotificationService : Service() {
@SuppressLint("ForegroundServiceType")
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (isRunning) {
stopSelf()
return START_NOT_STICKY
if (!isRunning) {
val notification = createPermanentNotification(applicationContext)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(1, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
} else {
startForeground(1, notification)
}
isRunning = true
}
val notification = createPermanentNotification(applicationContext)
startForeground(1, notification)
return START_STICKY
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment