Commit 608fb08e authored by wanglei's avatar wanglei

...

parent a28d928c
...@@ -8,6 +8,7 @@ import android.app.PendingIntent ...@@ -8,6 +8,7 @@ import android.app.PendingIntent
import android.app.Service import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.pm.ServiceInfo
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.graphics.drawable.Icon import android.graphics.drawable.Icon
import android.os.Build import android.os.Build
...@@ -37,7 +38,7 @@ class StayNotificationService : Service() { ...@@ -37,7 +38,7 @@ class StayNotificationService : Service() {
fun Context.startStayNotification() { fun Context.startStayNotification() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.TIRAMISU) {
return
} }
val intent = Intent(this, StayNotificationService::class.java) val intent = Intent(this, StayNotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
...@@ -51,13 +52,17 @@ class StayNotificationService : Service() { ...@@ -51,13 +52,17 @@ class StayNotificationService : Service() {
@SuppressLint("ForegroundServiceType") @SuppressLint("ForegroundServiceType")
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (isRunning) {
stopSelf() if (!isRunning) {
return START_NOT_STICKY 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 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