Compare commits

...

2 Commits

Author SHA1 Message Date
2c3b570dad 定位数据本地化保存 2024-07-16 11:02:49 +08:00
b29e3eaf03 修复上传位置00问题 2024-07-16 08:57:03 +08:00
6 changed files with 1688 additions and 31 deletions

View File

@ -11,6 +11,7 @@
<!-- 录音 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<!--播音-->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
@ -268,7 +269,8 @@
android:value="${GAODEKEY}" />
<!-- android:value="702eaa84675618b8eb69298d9fd42ca3" />-->
<service android:name="com.amap.api.location.APSService"></service>
<service android:name="com.amap.api.location.APSService"
android:foregroundServiceType="location"></service>
<!--百度地图-->
<meta-data

View File

@ -78,29 +78,30 @@ public class App extends Application {
}
}
// PendingIntent pendingIntent =
// PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
// Cactus.getInstance()
// .isDebug(true)
// //可选设置通知栏点击事件
// .setPendingIntent(pendingIntent)
//// .setBackgroundMusicEnabled(true)//可选退到后台是否可以播放音乐
//// .setMusicId(R.raw.main) //可选设置音乐
//// .setPendingIntent(pendingIntent)//可选设置通知栏点击事件
//// .addCallback(new CactusCallback())//可选运行时回调
// .setCrashRestartUIEnabled(true) //可选设置奔溃可以重启google原生rom android 10以下可以正常重启
// .setCrashRestartUIEnabled(true)//可选设置奔溃可以重启google原生rom android 10以下可以正常重启
// .setTitle("大河好运")
// .setSmallIcon(R.drawable.diver_logo)
// .addBackgroundCallback(new CactusBackgroundCallback() {
// @Override
// public void onBackground(boolean b) {
// if (b){
// getBillLocation();
// }
// }
// })
// .register(this);
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
Cactus.getInstance()
.isDebug(true)
//可选设置通知栏点击事件
.setPendingIntent(pendingIntent)
.setBackgroundMusicEnabled(true)//可选退到后台是否可以播放音乐
.setMusicId(R.raw.main) //可选设置音乐
// .setPendingIntent(pendingIntent)//可选设置通知栏点击事件
// .addCallback(new CactusCallback())//可选运行时回调
.setCrashRestartUIEnabled(true) //可选设置奔溃可以重启google原生rom android 10以下可以正常重启
.setCrashRestartUIEnabled(true)//可选设置奔溃可以重启google原生rom android 10以下可以正常重启
.setTitle("大河好运")
.setContent("大河好运司机端为您提供服务")
.setSmallIcon(R.drawable.diver_logo)
.addBackgroundCallback(new CactusBackgroundCallback() {
@Override
public void onBackground(boolean b) {
if (b){
getBillLocation();
}
}
})
.register(this);
}
public static App getApp() {

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,15 @@ package com.arpa.hndahesudintocctmsdriver.service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
import com.amap.api.location.AMapLocation;
import com.arpa.hndahesudintocctmsdriver.util.FileIOUtils;
import com.google.gson.Gson;
import com.arpa.hndahesudintocctmsdriver.bean.BaseBean;
import com.arpa.hndahesudintocctmsdriver.request.HuoYuanRequset;
@ -18,8 +21,13 @@ import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
import com.arpa.hndahesudintocctmsdriver.util.cache.CacheGroup;
import com.arpa.hndahesudintocctmsdriver.util.http.RequsetCodeConstants;
import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Filter;
/**
* @author hlh
@ -32,7 +40,7 @@ public class TrackService extends Service {
private Context con;
private TrackInputBean tib=new TrackInputBean();
private LocationGDUtil l;
private int timeSum=1000*60*3;
private int timeSum=1000*60;
private String snn="";
private Gson gson=new Gson();
private HuoYuanRequset hyr;
@ -51,7 +59,30 @@ public class TrackService extends Service {
}
break;
case LocationGDUtil.RES:
genzong();
if(CacheGroup.cacheList.get("getLocation")!=null){
AMapLocation location = gson.fromJson(CacheGroup.cacheList.get("getLocation"), AMapLocation.class);
String time2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
// 当前时间:${time2},经纬度:${it.latitude}:${it.longitude}
FileIOUtils.writeFileFromString(
Environment.getExternalStorageDirectory()
.toString() + "/crashinfo/" + "crash-"+time+".txt",
"当前时间:"+time2+",经纬度:"+location.getLatitude()+":"+location.getLongitude(),
true
);
// genzong(location);
CacheGroup.cacheList.remove("getLocation");
}
break;
case 16:
String time2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
FileIOUtils.writeFileFromString(
Environment.getExternalStorageDirectory()
.toString() + "/crashinfo/" + "crash-"+time+".txt",
"当前时间:"+time2+",定位失败",
true
);
break;
}
return false;
@ -94,13 +125,13 @@ public class TrackService extends Service {
super.onDestroy();
}
public void genzong(){
public void genzong(AMapLocation location){
//经度
tib.setLatitude(l.getLatitude()+"");
tib.setLatitude(location.getLatitude()+"");
//纬度
tib.setLongitude(l.getLongitude()+"");
Log.e("经度",l.getLatitude()+"");
Log.e("维度",l.getLongitude()+"");
tib.setLongitude(location.getLongitude()+"");
Log.e("经度",location.getLatitude()+"");
Log.e("维度",location.getLongitude()+"");
//单号
tib.setShippingNoteNumber(snn);
hyr.trackTracking(tib);

View File

@ -0,0 +1,240 @@
package com.arpa.hndahesudintocctmsdriver.util;
import com.arpa.hndahesudintocctmsdriver.FileUtils;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
/**
* @ClassName FileIOUtils
* @Author john
* @Date 2024/3/29 09:50
* @Description TODO
*/
public class FileIOUtils {
private FileIOUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
private static final String LINE_SEP = System.getProperty("line.separator");
/**
* 将输入流写入文件
*
* @param filePath 路径
* @param is 输入流
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(String filePath, final InputStream is) {
return writeFileFromIS(FileUtils.getFileByPath(filePath), is, false);
}
/**
* 将输入流写入文件
*
* @param filePath 路径
* @param is 输入流
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(String filePath, final InputStream is, boolean append) {
return writeFileFromIS(FileUtils.getFileByPath(filePath), is, append);
}
/**
* 将输入流写入文件
*
* @param file 文件
* @param is 输入流
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(File file, final InputStream is) {
return writeFileFromIS(file, is, false);
}
/**
* 将输入流写入文件
*
* @param file 文件
* @param is 输入流
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromIS(File file, final InputStream is, boolean append) {
if (!FileUtils.createOrExistsFile(file) || is == null) return false;
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(file, append));
byte data[] = new byte[1024];
int len;
while ((len = is.read(data, 0, 1024)) != -1) {
os.write(data, 0, len);
}
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
try {
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 将字符串写入文件
*
* @param filePath 文件路径
* @param content 写入内容
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(String filePath, String content) {
return writeFileFromString(FileUtils.getFileByPath(filePath), content, false);
}
/**
* 将字符串写入文件
*
* @param filePath 文件路径
* @param content 写入内容
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(String filePath, String content, boolean append) {
return writeFileFromString(FileUtils.getFileByPath(filePath), content, append);
}
/**
* 将字符串写入文件
*
* @param file 文件
* @param content 写入内容
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(File file, String content) {
return writeFileFromString(file, content, false);
}
/**
* 将字符串写入文件
*
* @param file 文件
* @param content 写入内容
* @param append 是否追加在文件末
* @return {@code true}: 写入成功<br>{@code false}: 写入失败
*/
public static boolean writeFileFromString(File file, String content, boolean append) {
if (file == null || content == null) return false;
if (!FileUtils.createOrExistsFile(file)) return false;
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new FileWriter(file, append));
bw.write(content);
bw.newLine();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 读取文件到字符串中
*
* @param filePath 文件路径
* @return 字符串
*/
public static String readFile2String(String filePath) {
return readFile2String(FileUtils.getFileByPath(filePath), null);
}
/**
* 读取文件到字符串中
*
* @param filePath 文件路径
* @param charsetName 编码格式
* @return 字符串
*/
public static String readFile2String(String filePath, String charsetName) {
return readFile2String(FileUtils.getFileByPath(filePath), charsetName);
}
/**
* 读取文件到字符串中
*
* @param file 文件
* @return 字符串
*/
public static String readFile2String(File file) {
return readFile2String(file, null);
}
/**
* 读取文件到字符串中
*
* @param file 文件
* @param charsetName 编码格式
* @return 字符串
*/
public static String readFile2String(File file, String charsetName) {
if (!FileUtils.isFileExists(file)) return null;
BufferedReader reader = null;
try {
StringBuilder sb = new StringBuilder();
if (isSpace(charsetName)) {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
} else {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName));
}
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append(LINE_SEP);
}
// delete the last line separator
return sb.delete(sb.length() - LINE_SEP.length(), sb.length()).toString();
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static boolean isSpace(String s) {
if (s == null) return true;
for (int i = 0, len = s.length(); i < len; ++i) {
if (!Character.isWhitespace(s.charAt(i))) {
return false;
}
}
return true;
}
}

View File

@ -8,7 +8,9 @@ import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.arpa.hndahesudintocctmsdriver.util.cache.CacheGroup;
import com.arpa.hndahesudintocctmsdriver.util.msg.MsgUtil;
import com.google.gson.Gson;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -74,6 +76,7 @@ public class LocationGDUtil {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(aMapLocation.getTime());
df.format(date);
CacheGroup.cacheList.put("getLocation",new Gson().toJson(aMapLocation));
MsgUtil.addHdMsgWat(hd,RES);
if (mLocationClient!=null) {
mLocationClient.onDestroy();