94 lines
2.3 KiB
Java
94 lines
2.3 KiB
Java
package com.arpa.hndahesudintocctmsdriver.service;
|
|
|
|
import android.app.Service;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.util.Log;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.arpa.hndahesudintocctmsdriver.request.HuoYuanRequset;
|
|
import com.arpa.hndahesudintocctmsdriver.request.bean.TrackInputBean;
|
|
import com.arpa.hndahesudintocctmsdriver.util.location.LocationGDUtil;
|
|
import com.arpa.hndahesudintocctmsdriver.util.http.RequsetCodeConstants;
|
|
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
/**
|
|
* @author hlh
|
|
* @version 1.0.0
|
|
* @date 2021/11/15 17:13
|
|
* @description:
|
|
*/
|
|
public class LocationService extends Service {
|
|
|
|
private Context con;
|
|
private TrackInputBean tib=new TrackInputBean();
|
|
private LocationGDUtil l;
|
|
private int timeSum=1000*5;
|
|
private String snn="";
|
|
private Gson gson=new Gson();
|
|
private HuoYuanRequset hyr;
|
|
private Handler hd=new Handler(msg -> {
|
|
switch (msg.what){
|
|
case RequsetCodeConstants.SUCCESS:
|
|
|
|
break;
|
|
case LocationGDUtil.RES:
|
|
genzong();
|
|
break;
|
|
}
|
|
return false;
|
|
});
|
|
|
|
@Nullable
|
|
@Override
|
|
public IBinder onBind(Intent intent) {return null; }
|
|
|
|
@Override
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
con=this;
|
|
hyr=new HuoYuanRequset(con,hd);
|
|
Log.e("开始循环上传,等待100ms","-----");
|
|
new Timer().schedule(new TimerTask() {
|
|
@Override
|
|
public void run() {
|
|
l = new LocationGDUtil(con, hd);
|
|
l.onCreate();
|
|
}
|
|
},100,timeSum);
|
|
}
|
|
|
|
//开始
|
|
@Override
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
Log.e("服务开启","-----");
|
|
return START_STICKY;
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onDestroy() {
|
|
super.onDestroy();
|
|
}
|
|
|
|
|
|
int sum=0;
|
|
public void genzong(){
|
|
//经度
|
|
tib.setLatitude(l.getLatitude()+"");
|
|
//纬度
|
|
tib.setLongitude(l.getLongitude()+"");
|
|
Log.e("经度",l.getLatitude()+"");
|
|
Log.e("维度",l.getLongitude()+"");
|
|
sum+=3;
|
|
Log.e("当前app后台服务存活时间(手机息屏状态)",sum+"秒");
|
|
}
|
|
|
|
}
|