定位数据本地化保存
This commit is contained in:
parent
b29e3eaf03
commit
2c3b570dad
@ -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
|
||||
|
@ -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() {
|
||||
|
1380
app/src/main/java/com/arpa/hndahesudintocctmsdriver/FileUtils.java
Normal file
1380
app/src/main/java/com/arpa/hndahesudintocctmsdriver/FileUtils.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ 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;
|
||||
@ -10,6 +11,7 @@ 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;
|
||||
@ -19,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
|
||||
@ -33,7 +40,7 @@ public class TrackService extends Service {
|
||||
private Context con;
|
||||
private TrackInputBean tib=new TrackInputBean();
|
||||
private LocationGDUtil l;
|
||||
private int timeSum=1000*10;
|
||||
private int timeSum=1000*60;
|
||||
private String snn="";
|
||||
private Gson gson=new Gson();
|
||||
private HuoYuanRequset hyr;
|
||||
@ -54,10 +61,29 @@ public class TrackService extends Service {
|
||||
case LocationGDUtil.RES:
|
||||
if(CacheGroup.cacheList.get("getLocation")!=null){
|
||||
AMapLocation location = gson.fromJson(CacheGroup.cacheList.get("getLocation"), AMapLocation.class);
|
||||
genzong(location);
|
||||
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;
|
||||
});
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user