Commit a748883a authored by wanglei's avatar wanglei

...

parent 6072b4d3
......@@ -32,15 +32,14 @@ import com.base.pdfviewerscannerwhite.utils.LogEx
class StayJobService : JobService() {
init {
val builder = Configuration.Builder()
builder.setJobSchedulerJobIdRange(0, 1000)
}
private val TAG = "StayNotificationService"
val channelName = "PDF Reader Foreground Service Channel"
val channelId = "PDF_Reader_Service_Id"
val NOTIFICATION_PERMANENT_ID = 186
private val TAG = "StayJobService"
private val channelName = "PDF Reader Foreground Service Channel"
private val channelId = "PDF_Reader_Service_Id"
private val NOTIFICATION_PERMANENT_ID = 186
companion object {
......@@ -111,6 +110,7 @@ class StayJobService : JobService() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
//监听媒体库变化
observerMediaContentObserver()
......@@ -132,6 +132,15 @@ class StayJobService : JobService() {
isRunning = true
}
private fun notifyForeground() {
val notificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(
NOTIFICATION_PERMANENT_ID,
createPermanentNotification(applicationContext)
)
}
override fun onDestroy() {
isRunning = false
......@@ -139,12 +148,11 @@ class StayJobService : JobService() {
}
override fun onCreate() {
LogEx.logDebug(TAG, "onCreate isRunning=$isRunning")
if (!isRunning) {
startForeground()
isRunning = true
Timer {
startForeground()
}.apply { start() }
startForeground()
Timer().start()
}
super.onCreate()
}
......@@ -157,6 +165,18 @@ class StayJobService : JobService() {
return false
}
private inner class Timer() : CountDownTimer(30000, 1000) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
notifyForeground()
Timer().start()
}
}
private var mediaContentObserver: MediaContentObserver? = null
private fun observerMediaContentObserver() {
......@@ -168,19 +188,8 @@ class StayJobService : JobService() {
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, true, it
)
}
}
}
}
class Timer(val block: () -> Unit) : CountDownTimer(30000, 1000) {
override fun onTick(millisUntilFinished: Long) {
}
override fun onFinish() {
Timer {
block()
}.apply { start() }
}
}
\ No newline at end of file
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