初始化
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
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.arpa.hndahesudintocctmsdriver.bean.StartOrderBean;
|
||||
import com.arpa.hndahesudintocctmsdriver.constant.JTTConstant;
|
||||
import com.arpa.hndahesudintocctmsdriver.report.JTTProcess;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.msg.MsgUtil;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.hdgq.locationlib.entity.ShippingNoteInfo;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/12/24 14:16
|
||||
* @description:
|
||||
*/
|
||||
public class JTTSendService extends Service {
|
||||
|
||||
private Context con;
|
||||
private String snn="";
|
||||
private Gson gson=new Gson();
|
||||
private StartOrderBean sob=null;
|
||||
|
||||
private Handler hd=new Handler(msg -> {
|
||||
switch (msg.what){
|
||||
case 66:
|
||||
JTTProcess.send(con,sob,"");
|
||||
break;
|
||||
case 67:
|
||||
JTTProcess.pause(getBaseContext(),sob,"");
|
||||
sob.getData().setCarNumber("豫PK2861");
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
MsgUtil.addHdMsgWat(hd,68);
|
||||
}
|
||||
},6000,100000000);
|
||||
break;
|
||||
case 68:
|
||||
JTTProcess.restart(getBaseContext(),sob,"[03]换车");
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {return null; }
|
||||
|
||||
private int sum=0;
|
||||
private ShippingNoteInfo sf;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.e("交通厅","开启位置上传");
|
||||
con=this;
|
||||
String str= SPUtil.getSP(con, JTTConstant.JTT_DATA_NAME,JTTConstant.JTT_DATA_JTTORDER_KEY);
|
||||
String str2=SPUtil.getSP(con,JTTConstant.JTT_DATA_NAME,JTTConstant.JTT_DATA_ORDER_KEY);
|
||||
sf=gson.fromJson(str,ShippingNoteInfo.class);
|
||||
sob=gson.fromJson(str2,StartOrderBean.class);
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
while (true){
|
||||
String str= SPUtil.getSP(con,JTTConstant.JTT_DATA_NAME,JTTConstant.JTT_DATA_JTTORDER_KEY);
|
||||
if ("".equals(str)) {
|
||||
break;
|
||||
}
|
||||
sf=gson.fromJson(str, ShippingNoteInfo.class);
|
||||
try {
|
||||
Thread.sleep(sf.getInterval()+1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
MsgUtil.addHdMsgWat(hd,66);
|
||||
try {
|
||||
Thread.sleep(6000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// sum++;
|
||||
// if(sum==3){
|
||||
// MsgUtil.addHdMsgWat(hd,67);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
//开始
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e("服务开启","-----");
|
||||
return START_STICKY;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
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+"秒");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
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.alct.mdp.MDPLocationCollectionManager;
|
||||
import com.alct.mdp.model.Image;
|
||||
import com.google.gson.Gson;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.msg.MsgUtil;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/11/23 20:31
|
||||
* @description:
|
||||
*/
|
||||
public class MakeUpAlService extends Service {
|
||||
|
||||
//装货照片 卸货照片 回单照片
|
||||
|
||||
private Context con;
|
||||
private Gson gson=new Gson();
|
||||
private int cd=60*1;
|
||||
private Handler hd=new Handler(msg -> {
|
||||
switch (msg.what){
|
||||
case 15:
|
||||
up();
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
con=getBaseContext();
|
||||
new Handler().postDelayed(() -> {
|
||||
MsgUtil.addHdMsgWat(hd,15);
|
||||
},cd);
|
||||
}
|
||||
|
||||
//开始
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e("服务开启","-----");
|
||||
return START_STICKY;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void up(){
|
||||
String id_1=SPUtil.getSP(con,"make","装货");
|
||||
String id_2=SPUtil.getSP(con,"make","卸货");
|
||||
String id_3=SPUtil.getSP(con,"make","回单");
|
||||
if(!"".equals(id_1)){
|
||||
String image_1=SPUtil.getSP(con,"make","装货-"+id_1);
|
||||
up_image_z(id_1,gson.fromJson(image_1,Image.class));
|
||||
}
|
||||
if(!"".equals(id_2)){
|
||||
String image_2=SPUtil.getSP(con,"make","卸货-"+id_2);
|
||||
up_image_z(id_2,gson.fromJson(image_2,Image.class));
|
||||
}
|
||||
if(!"".equals(id_3)){
|
||||
String image_3=SPUtil.getSP(con,"make","回单-"+id_3);
|
||||
up_image_z(id_3,gson.fromJson(image_3,Image.class));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void up_image_z(String id,Image image){
|
||||
MDPLocationCollectionManager.uploadPickupImage(con,id,image, new com.alct.mdp.callback.OnResultListener() {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Log.e("上报安联","装货照片上传成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String s, String s1) {
|
||||
Log.e("上报安联失败(装货照片):",s+s1);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void up_image(String id,Image image){
|
||||
MDPLocationCollectionManager.uploadUnloadImage(con,id, image, new com.alct.mdp.callback.OnResultListener() {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Log.e("上报安联","卸货照片上传成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String s, String s1) {
|
||||
Log.e("上报安联失败(卸货照片):",s+s1);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public void receipt_image(String id,Image image){
|
||||
MDPLocationCollectionManager.uploadPODImage(con,id, image, new com.alct.mdp.callback.OnResultListener() {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Log.e("上报安联","回单照片上传成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(String s, String s1) {
|
||||
Log.e("上报安联失败(回单照片):",s+s1);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.request.HuoYuanRequset;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.cache.CacheGroup;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.http.RequsetCodeConstants;
|
||||
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/10/8 16:33
|
||||
* @description:上传失败后进行重新上传
|
||||
*/
|
||||
public class MakeUpService extends Service {
|
||||
|
||||
private MediaPlayer mediaPlayer = new MediaPlayer();
|
||||
public void palyMp3(){
|
||||
Log.e("开始播放","-----");
|
||||
try {
|
||||
AssetFileDescriptor fd =getAssets().openFd("kujp9scu.mp3");
|
||||
mediaPlayer.setDataSource(fd);
|
||||
mediaPlayer.setLooping(false);//设置为循环播放
|
||||
mediaPlayer.prepare();//初始化播放器MediaPlayer
|
||||
mediaPlayer.start();
|
||||
Log.e("播放成功","-----");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Log.e("播放失败","-----");
|
||||
}
|
||||
}
|
||||
private Handler hd=new Handler(msg -> {
|
||||
switch (msg.what){
|
||||
case RequsetCodeConstants.SUCCESS:
|
||||
if(CacheGroup.cacheList.get(HuoYuanRequset.ASYMMETRYWAYBILL)!=null){
|
||||
|
||||
CacheGroup.cacheList.remove(CacheGroup.cacheList.get(HuoYuanRequset.ASYMMETRYWAYBILL));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
palyMp3();
|
||||
}
|
||||
|
||||
//开始
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e("服务开启","-----");
|
||||
|
||||
return START_STICKY;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mediaPlayer!=null) {
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.release();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.R;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/9/10 11:17
|
||||
* @description:
|
||||
*/
|
||||
public class PlayerMusicService extends Service {
|
||||
private MediaPlayer mMediaPlayer;
|
||||
private boolean normalExit;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Context con;
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel mChannel = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
mChannel = new NotificationChannel("1", getString(R.string.app_name),
|
||||
NotificationManager.IMPORTANCE_LOW);
|
||||
notificationManager.createNotificationChannel(mChannel);
|
||||
Notification notification = new Notification.Builder(getApplicationContext(), "1").build();
|
||||
startForeground(1, notification);
|
||||
}
|
||||
normalExit = false;
|
||||
mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.silent);
|
||||
if (mMediaPlayer != null) {
|
||||
mMediaPlayer.setLooping(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startPlayMusic();
|
||||
}
|
||||
}).start();
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
||||
private void startPlayMusic() {
|
||||
if (mMediaPlayer == null) {
|
||||
mMediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.silent);
|
||||
|
||||
if (mMediaPlayer != null) {
|
||||
mMediaPlayer.setLooping(true);
|
||||
mMediaPlayer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void stopPlayMusic() {
|
||||
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
|
||||
mMediaPlayer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
stopPlayMusic();
|
||||
// 重启
|
||||
if (!normalExit) {
|
||||
Intent intent = new Intent(getApplicationContext(), PlayerMusicService.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(intent);
|
||||
} else {
|
||||
startService(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.MainActivity;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/8/31 19:54
|
||||
* @description:
|
||||
*/
|
||||
public class RestartService extends Service {
|
||||
|
||||
private Context con;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Service被启动的时候回调onStartCommand方法
|
||||
public int onStartCommand(Intent intent, int flags, int startId){
|
||||
Log.e("---static---","启动");
|
||||
return START_STICKY;
|
||||
}
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
con=getApplication();
|
||||
Intent in=new Intent(con, MainActivity.class);
|
||||
startActivity(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.arpa.hndahesudintocctmsdriver.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.TaskStackBuilder;
|
||||
|
||||
import com.arpa.hndahesudintocctmsdriver.R;
|
||||
import com.arpa.hndahesudintocctmsdriver.ui.login.WelcomeActivity;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/8/10 19:00
|
||||
* @description:
|
||||
*/
|
||||
public class TestService extends Service {
|
||||
|
||||
private Context con;
|
||||
private Handler hd=new Handler(msg -> {
|
||||
switch (msg.what){
|
||||
case 1:
|
||||
|
||||
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
//DanWeiBroadcastReceiver db;
|
||||
@Nullable
|
||||
@Override
|
||||
//想要使用Service必须实现这个方法,该方法返回一个IBinder对象
|
||||
//应用程序使用这个对象与Service组件进行通信
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Service被创建的时候回调onCreate方法
|
||||
public void onCreate(){
|
||||
super.onCreate();
|
||||
con=this;
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
notification("消息","您有一条新的订单");
|
||||
Log.e("1234","1234");
|
||||
}
|
||||
},100,5000);
|
||||
}
|
||||
|
||||
|
||||
//Service被启动的时候回调onStartCommand方法
|
||||
public int onStartCommand(Intent intent, int flags, int startId){
|
||||
Log.e("---static---","启动");
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
//Service被销毁的时候回调onDestroy方法
|
||||
public void onDestroy(){
|
||||
super.onDestroy();
|
||||
Log.e("---static---","关闭");
|
||||
Intent intentOne = new Intent(con,TestService.class);
|
||||
startService(intentOne);
|
||||
}
|
||||
|
||||
private void notification(String title,String value) {
|
||||
Intent intent = new Intent(this, WelcomeActivity.class);
|
||||
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
//8.0 以后需要加上channelId 才能正常显示
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
||||
String channelId = "default";
|
||||
String channelName = "默认通知";
|
||||
manager.createNotificationChannel(new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_HIGH));
|
||||
}
|
||||
//设置TaskStackBuilder
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
|
||||
stackBuilder.addParentStack(WelcomeActivity.class);
|
||||
stackBuilder.addNextIntent(intent);
|
||||
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
Notification notification = new NotificationCompat.Builder(this, "default")
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentTitle("您有一条新的订单")
|
||||
.setContentText(value)
|
||||
.setAutoCancel(true)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setContentIntent(pendingIntent)
|
||||
.build();
|
||||
manager.notify(1, notification);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
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.bean.BaseBean;
|
||||
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.sp.SPUtil;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.cache.CacheGroup;
|
||||
import com.arpa.hndahesudintocctmsdriver.util.http.RequsetCodeConstants;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @author hlh
|
||||
* @version 1.0.0
|
||||
* @date 2021/8/13 18:52
|
||||
* @description:上传司机轨迹位置
|
||||
*/
|
||||
public class TrackService extends Service {
|
||||
|
||||
private Context con;
|
||||
private TrackInputBean tib=new TrackInputBean();
|
||||
private LocationGDUtil l;
|
||||
private int timeSum=1000*60*3;
|
||||
private String snn="";
|
||||
private Gson gson=new Gson();
|
||||
private HuoYuanRequset hyr;
|
||||
|
||||
private Handler hd=new Handler(msg -> {
|
||||
switch (msg.what){
|
||||
case RequsetCodeConstants.SUCCESS:
|
||||
if(CacheGroup.cacheList.get("genzong")!=null){
|
||||
BaseBean bb=gson.fromJson(CacheGroup.cacheList.get("genzong"),BaseBean.class);
|
||||
if(bb.getCode()==200){
|
||||
Log.e("--轨迹上传--","成功");
|
||||
}else{
|
||||
Log.e("--轨迹上传失败:--",bb.getMsg());
|
||||
}
|
||||
CacheGroup.cacheList.remove("genzong");
|
||||
}
|
||||
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() {
|
||||
snn=SPUtil.getSP(con,"order","ShippingNoteNumber");
|
||||
if(!snn.equals("")) {
|
||||
l = new LocationGDUtil(con, hd);
|
||||
l.onCreate();
|
||||
}else{
|
||||
onDestroy();
|
||||
}
|
||||
}
|
||||
},100,timeSum);
|
||||
}
|
||||
|
||||
//开始
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e("服务开启","-----");
|
||||
return START_STICKY;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public void genzong(){
|
||||
//经度
|
||||
tib.setLatitude(l.getLatitude()+"");
|
||||
//纬度
|
||||
tib.setLongitude(l.getLongitude()+"");
|
||||
Log.e("经度",l.getLatitude()+"");
|
||||
Log.e("维度",l.getLongitude()+"");
|
||||
//单号
|
||||
tib.setShippingNoteNumber(snn);
|
||||
hyr.trackTracking(tib);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user