Commit 8f2aafeb authored by wanglei's avatar wanglei

...前台服务

parent 94bae9ec
...@@ -30,12 +30,12 @@ class StayJobService : JobService() { ...@@ -30,12 +30,12 @@ class StayJobService : JobService() {
companion object { companion object {
private val TAG = "StayJobService" private val TAG = "StayJobService"
val NOTIFICATION_PERMANENT_ID = 186 val NOTIFICATION_STAY_ID = 186
private var isRunning = false private var isRunning = false
private const val JOB_INFO_ID: Int = 101 private const val JOB_INFO_ID: Int = 101
private const val JOB_PERIODIC: Long = 5 * 1000L
fun Context.startJob() { fun Context.startJob() {
if (isRunning) return if (isRunning) return
LogEx.logDebug(TAG, "startJob") LogEx.logDebug(TAG, "startJob")
...@@ -59,12 +59,12 @@ class StayJobService : JobService() { ...@@ -59,12 +59,12 @@ class StayJobService : JobService() {
val notification = createPermanentNotification(applicationContext) val notification = createPermanentNotification(applicationContext)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground( startForeground(
NOTIFICATION_PERMANENT_ID, NOTIFICATION_STAY_ID,
notification, notification,
ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION
) )
} else { } else {
startForeground(NOTIFICATION_PERMANENT_ID, notification) startForeground(NOTIFICATION_STAY_ID, notification)
} }
isRunning = true isRunning = true
} }
...@@ -74,7 +74,7 @@ class StayJobService : JobService() { ...@@ -74,7 +74,7 @@ class StayJobService : JobService() {
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify( notificationManager.notify(
NOTIFICATION_PERMANENT_ID, NOTIFICATION_STAY_ID,
createPermanentNotification(applicationContext) createPermanentNotification(applicationContext)
) )
} }
......
...@@ -13,7 +13,7 @@ import android.widget.RemoteViews ...@@ -13,7 +13,7 @@ import android.widget.RemoteViews
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.graphics.drawable.IconCompat import androidx.core.graphics.drawable.IconCompat
import com.base.appzxhy.R import com.base.appzxhy.R
import com.base.appzxhy.service.StayJobService.Companion.NOTIFICATION_PERMANENT_ID import com.base.appzxhy.service.StayJobService.Companion.NOTIFICATION_STAY_ID
import com.base.appzxhy.ui.main.MainActivity import com.base.appzxhy.ui.main.MainActivity
object StayNotification { object StayNotification {
...@@ -85,7 +85,7 @@ object StayNotification { ...@@ -85,7 +85,7 @@ object StayNotification {
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify( notificationManager.notify(
NOTIFICATION_PERMANENT_ID, NOTIFICATION_STAY_ID,
createPermanentNotification(context) createPermanentNotification(context)
) )
......
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