desc:模拟心跳
parent
34535f4613
commit
9b5aef0f14
@ -0,0 +1,38 @@
|
|||||||
|
package com.yinuo.safetywatcher.watcher.services
|
||||||
|
|
||||||
|
import android.app.IntentService
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
|
private const val ACTION_START = "com.yinuo.safetywatcher.watcher.services.action.Heartbeat"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模拟心跳
|
||||||
|
*/
|
||||||
|
class HeartbeatService : IntentService("HeartbeatService") {
|
||||||
|
|
||||||
|
override fun onHandleIntent(intent: Intent?) {
|
||||||
|
when (intent?.action) {
|
||||||
|
ACTION_START -> {
|
||||||
|
handleActionStart(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleActionStart(intent: Intent) {
|
||||||
|
Log.i("cyy", "heartBeat")
|
||||||
|
Thread.sleep(30000)
|
||||||
|
handleActionStart(intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun startActionStart(context: Context) {
|
||||||
|
val intent = Intent(context, HeartbeatService::class.java).apply {
|
||||||
|
action = ACTION_START
|
||||||
|
}
|
||||||
|
context.startService(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue