package com.doumee.keyCabinet.ui.service;
|
|
|
import android.app.Service;
|
import android.content.Intent;
|
import android.os.CountDownTimer;
|
import android.os.IBinder;
|
|
import androidx.annotation.Nullable;
|
|
import com.doumee.keyCabinet.event.GetFacesEvent;
|
|
import org.greenrobot.eventbus.EventBus;
|
import org.json.JSONException;
|
|
import timber.log.Timber;
|
|
/**
|
* 人脸同步服务
|
*/
|
public class FaceUpdateService extends Service {
|
private CountDownTimer countTimer;
|
|
@Override
|
public void onCreate() {
|
//Log.i("Kathy","onCreate - Thread ID = " + Thread.currentThread().getId());
|
super.onCreate();
|
}
|
|
@Override
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
if(countTimer==null){
|
countTimer = new CountDownTimer(30000, 30000) {
|
@Override
|
public void onTick(long millisUntilFinished) {
|
//Timber.tag("CountTimer==>更新人脸").d(millisUntilFinished+"");
|
}
|
|
@Override
|
public void onFinish() {
|
Timber.tag("CountTimer==>").d("更新人脸 onFinish");
|
try {
|
sendPost();
|
} catch (JSONException e) {
|
|
}
|
}
|
};
|
}
|
if(countTimer!=null){
|
countTimer.start();
|
}
|
return super.onStartCommand(intent, flags, startId);
|
}
|
|
@Nullable
|
@Override
|
public IBinder onBind(Intent intent) {
|
//Log.i("Kathy", "onBind - Thread ID = " + Thread.currentThread().getId());
|
return null;
|
}
|
|
@Override
|
public void onDestroy() {
|
//Log.i("Kathy", "onDestroy - Thread ID = " + Thread.currentThread().getId());
|
super.onDestroy();
|
if(countTimer!=null){
|
countTimer.cancel();
|
countTimer = null;
|
}
|
}
|
|
private void sendPost() throws JSONException {
|
EventBus.getDefault().post(new GetFacesEvent());
|
if(countTimer!=null){
|
countTimer.start();
|
}
|
}
|
}
|