|
|
@ -4,7 +4,9 @@ import android.annotation.SuppressLint
|
|
|
|
import android.app.IntentService
|
|
|
|
import android.app.IntentService
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent
|
|
|
|
import com.yinuo.safetywatcher.watcher.net.HeartbeatApi
|
|
|
|
import com.common.commonlib.net.callback.RequestResultCallBack
|
|
|
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.bean.GetRtspUrlResponse
|
|
|
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.net.DevicesApi
|
|
|
|
import com.yinuo.safetywatcher.watcher.utils.LztekUtil
|
|
|
|
import com.yinuo.safetywatcher.watcher.utils.LztekUtil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -15,8 +17,8 @@ private const val ACTION_START = "com.yinuo.safetywatcher.watcher.services.actio
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class HeartbeatService : IntentService("HeartbeatService") {
|
|
|
|
class HeartbeatService : IntentService("HeartbeatService") {
|
|
|
|
|
|
|
|
|
|
|
|
private val heartbeatApi by lazy {
|
|
|
|
private val devicesApi by lazy {
|
|
|
|
HeartbeatApi()
|
|
|
|
DevicesApi()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onHandleIntent(intent: Intent?) {
|
|
|
|
override fun onHandleIntent(intent: Intent?) {
|
|
|
@ -29,14 +31,30 @@ class HeartbeatService : IntentService("HeartbeatService") {
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("HardwareIds")
|
|
|
|
@SuppressLint("HardwareIds")
|
|
|
|
private fun handleActionStart(intent: Intent) {
|
|
|
|
private fun handleActionStart(intent: Intent) {
|
|
|
|
heartbeatApi.heartBeat(LztekUtil.getSn())
|
|
|
|
devicesApi.heartBeat(LztekUtil.getSn())
|
|
|
|
|
|
|
|
checkAndGetRtspUrl()
|
|
|
|
Thread.sleep(30000)
|
|
|
|
Thread.sleep(30000)
|
|
|
|
handleActionStart(intent)
|
|
|
|
handleActionStart(intent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun checkAndGetRtspUrl() {
|
|
|
|
|
|
|
|
if (LztekUtil.getRtspUrl().isNullOrEmpty()) {
|
|
|
|
|
|
|
|
devicesApi.getPushUrl(
|
|
|
|
|
|
|
|
LztekUtil.getSn(),
|
|
|
|
|
|
|
|
object : RequestResultCallBack<GetRtspUrlResponse>() {
|
|
|
|
|
|
|
|
override fun onResult(result: GetRtspUrlResponse) {
|
|
|
|
|
|
|
|
LztekUtil.setRtspUrl(result.data)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onError(error: String?) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
companion object {
|
|
|
|
@JvmStatic
|
|
|
|
@JvmStatic
|
|
|
|
fun startActionStart(context: Context) {
|
|
|
|
fun actionStart(context: Context) {
|
|
|
|
val intent = Intent(context, HeartbeatService::class.java).apply {
|
|
|
|
val intent = Intent(context, HeartbeatService::class.java).apply {
|
|
|
|
action = ACTION_START
|
|
|
|
action = ACTION_START
|
|
|
|
}
|
|
|
|
}
|
|
|
|