fix: 增加全局异常记录
This commit is contained in:
parent
11289fb08a
commit
f7943db1c0
@ -12,8 +12,8 @@ android {
|
|||||||
applicationId "com.navinfo.outdoor"
|
applicationId "com.navinfo.outdoor"
|
||||||
minSdkVersion 24
|
minSdkVersion 24
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode 46
|
versionCode 47
|
||||||
versionName "8.230214"
|
versionName "8.230216"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
ndk {
|
ndk {
|
||||||
|
@ -506,7 +506,10 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
|||||||
@Override
|
@Override
|
||||||
public void onMapClick(LatLng latLng) {
|
public void onMapClick(LatLng latLng) {
|
||||||
Message msg = handler.obtainMessage(0x105);
|
Message msg = handler.obtainMessage(0x105);
|
||||||
msg.obj = TencentLocationObtain.obtainTecentLocation(latLng);
|
Location location = new Location("GPS");
|
||||||
|
location.setLongitude(latLng.getLongitude());
|
||||||
|
location.setLatitude(latLng.getLatitude());
|
||||||
|
msg.obj = TencentLocationObtain.obtainTecentLocation(location);
|
||||||
handler.sendMessage(msg);
|
handler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -48,6 +48,7 @@ import android.content.Intent;
|
|||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
@ -8,8 +8,6 @@ import android.content.Intent;
|
|||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.lifecycle.ProcessLifecycleOwner;
|
|
||||||
|
|
||||||
import com.lzy.okgo.OkGo;
|
import com.lzy.okgo.OkGo;
|
||||||
import com.lzy.okgo.cache.CacheEntity;
|
import com.lzy.okgo.cache.CacheEntity;
|
||||||
import com.lzy.okgo.cache.CacheMode;
|
import com.lzy.okgo.cache.CacheMode;
|
||||||
@ -17,6 +15,7 @@ import com.lzy.okgo.cookie.CookieJarImpl;
|
|||||||
import com.lzy.okgo.cookie.store.DBCookieStore;
|
import com.lzy.okgo.cookie.store.DBCookieStore;
|
||||||
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
|
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
|
||||||
import com.lzy.okgo.model.HttpHeaders;
|
import com.lzy.okgo.model.HttpHeaders;
|
||||||
|
import com.navinfo.outdoor.util.CrashHandler;
|
||||||
import com.tencent.map.navi.TencentNavi;
|
import com.tencent.map.navi.TencentNavi;
|
||||||
import com.tencent.navi.surport.utils.DeviceUtils;
|
import com.tencent.navi.surport.utils.DeviceUtils;
|
||||||
import com.tencent.tencentmap.mapsdk.maps.TencentMapInitializer;
|
import com.tencent.tencentmap.mapsdk.maps.TencentMapInitializer;
|
||||||
@ -62,7 +61,7 @@ public class UserApplication extends Application {
|
|||||||
config.setDeviceId(deviceID);
|
config.setDeviceId(deviceID);
|
||||||
// 或者设置开发者自己的的设备号config.setDeviceId(xxxxxxxx);
|
// 或者设置开发者自己的的设备号config.setDeviceId(xxxxxxxx);
|
||||||
TencentNavi.init(this, config);
|
TencentNavi.init(this, config);
|
||||||
|
CrashHandler.getInstance().init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserApplication getUserApplication() {
|
public static UserApplication getUserApplication() {
|
||||||
|
@ -2,9 +2,9 @@ package com.navinfo.outdoor.http;
|
|||||||
|
|
||||||
public class HttpInterface {
|
public class HttpInterface {
|
||||||
// public static final String IP = "http://172.23.138.133:9999/m4";//测试接口-IP
|
// public static final String IP = "http://172.23.138.133:9999/m4";//测试接口-IP
|
||||||
public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网
|
public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网
|
||||||
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网
|
public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网
|
||||||
public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
|
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
|
||||||
public static final String USER_PATH = "/user/";//我的
|
public static final String USER_PATH = "/user/";//我的
|
||||||
public static final String MSG_LIST_PATH = "/msgList/";//发现
|
public static final String MSG_LIST_PATH = "/msgList/";//发现
|
||||||
public static final String USER_LOGIN_PATH = "/userlogin/";//登录
|
public static final String USER_LOGIN_PATH = "/userlogin/";//登录
|
||||||
|
92
app/src/main/java/com/navinfo/outdoor/util/CrashHandler.java
Normal file
92
app/src/main/java/com/navinfo/outdoor/util/CrashHandler.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package com.navinfo.outdoor.util;
|
||||||
|
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.os.SystemClock;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.elvishew.xlog.XLog;
|
||||||
|
import com.navinfo.outdoor.api.UserApplication;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
|
||||||
|
public class CrashHandler implements Thread.UncaughtExceptionHandler {
|
||||||
|
|
||||||
|
private static volatile CrashHandler INSTANCE;
|
||||||
|
|
||||||
|
private CrashHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CrashHandler getInstance() {
|
||||||
|
if (INSTANCE == null) {
|
||||||
|
synchronized (CrashHandler.class) {
|
||||||
|
if (INSTANCE == null) {
|
||||||
|
synchronized (CrashHandler.class) {
|
||||||
|
INSTANCE = new CrashHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Thread.UncaughtExceptionHandler mDefaultHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化默认异常捕获
|
||||||
|
*/
|
||||||
|
public void init() {
|
||||||
|
// 获取默认异常处理器
|
||||||
|
mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||||
|
// 将当前类设为默认异常处理器
|
||||||
|
Thread.setDefaultUncaughtExceptionHandler(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
|
if (handleException(e)) {
|
||||||
|
Toast.makeText(UserApplication.getUserApplication(), "抱歉,出现不可预知错误,请联系工作人员!", Toast.LENGTH_SHORT).show();
|
||||||
|
// 已经处理,APP重启
|
||||||
|
restartApp();
|
||||||
|
} else {
|
||||||
|
// 如果不处理,则调用系统默认处理异常,弹出系统强制关闭的对话框
|
||||||
|
if (mDefaultHandler != null) {
|
||||||
|
mDefaultHandler.uncaughtException(t, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean handleException(Throwable e) {
|
||||||
|
if (e == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Writer writer = new StringWriter();
|
||||||
|
PrintWriter pw = new PrintWriter(writer);
|
||||||
|
e.printStackTrace(pw);
|
||||||
|
pw.close();
|
||||||
|
String result = writer.toString();
|
||||||
|
// 打印出错误日志
|
||||||
|
XLog.e(result);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1s后让APP重启
|
||||||
|
*/
|
||||||
|
private void restartApp() {
|
||||||
|
Intent intent = UserApplication.getUserApplication().getPackageManager()
|
||||||
|
.getLaunchIntentForPackage(UserApplication.getUserApplication().getPackageName());
|
||||||
|
PendingIntent restartIntent = PendingIntent.getActivity(UserApplication.getUserApplication(), 0, intent, 0);
|
||||||
|
AlarmManager mgr = (AlarmManager) UserApplication.getUserApplication().getSystemService(Context.ALARM_SERVICE);
|
||||||
|
// 1秒钟后重启应用
|
||||||
|
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent);
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,9 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
import com.navinfo.outdoor.api.Constant;
|
import com.navinfo.outdoor.api.Constant;
|
||||||
|
import com.tencent.map.fusionlocation.model.TencentGeoLocation;
|
||||||
|
import com.tencent.map.geolocation.TencentLocation;
|
||||||
|
import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
@ -171,10 +174,12 @@ public class GPSUtils {
|
|||||||
Log.i(TAG, "纬度:" + location.getLatitude());
|
Log.i(TAG, "纬度:" + location.getLatitude());
|
||||||
Log.i(TAG, "海拔:" + location.getAltitude());
|
Log.i(TAG, "海拔:" + location.getAltitude());
|
||||||
|
|
||||||
|
TencentLocation tencentLocation = TencentLocationObtain.obtainTecentLocation(location);
|
||||||
|
|
||||||
Message currentLocationMsg = Message.obtain();
|
Message currentLocationMsg = Message.obtain();
|
||||||
currentLocationMsg.what = Constant.EVENT_WHAT_LOCATION_CHANGE;
|
currentLocationMsg.what = Constant.EVENT_WHAT_LOCATION_CHANGE;
|
||||||
currentLocationMsg.arg1 = LocationLifeCycle.LOCATION_FROM.ORIGIN.ordinal(); // 设置定位来源
|
currentLocationMsg.arg1 = LocationLifeCycle.LOCATION_FROM.ORIGIN.ordinal(); // 设置定位来源
|
||||||
currentLocationMsg.obj = location;
|
currentLocationMsg.obj = tencentLocation;
|
||||||
EventBus.getDefault().post(currentLocationMsg);
|
EventBus.getDefault().post(currentLocationMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public class LocationLifeCycle implements DefaultLifecycleObserver {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private LOCATION_FROM mainLocationFrom = LOCATION_FROM.TENCENT/*主要位置源*/, referenceLocationFrom = LOCATION_FROM.ORIGIN/*参考位置源*/;
|
private LOCATION_FROM mainLocationFrom = LOCATION_FROM.TENCENT/*主要位置源*/, referenceLocationFrom = LOCATION_FROM.ORIGIN/*参考位置源*/;
|
||||||
private TencentLocation tencentLocation; // 腾讯定位获取到的最新位置信息
|
private TencentLocation tencentLocation; // 腾讯定位获取到的最新位置信息
|
||||||
private Location gpsLocation; // 原生系统获取到的最新位置
|
private TencentLocation gpsLocation; // 原生系统获取到的最新位置
|
||||||
private List<LocationSource.OnLocationChangedListener> locationChangedListenerList;
|
private List<LocationSource.OnLocationChangedListener> locationChangedListenerList;
|
||||||
private static LocationLifeCycle instance;
|
private static LocationLifeCycle instance;
|
||||||
|
|
||||||
@ -80,11 +80,21 @@ public class LocationLifeCycle implements DefaultLifecycleObserver {
|
|||||||
public void onEventMessageMainThread(Message msg) {
|
public void onEventMessageMainThread(Message msg) {
|
||||||
if (msg.what == Constant.EVENT_WHAT_LOCATION_CHANGE) { // 用户位置更新
|
if (msg.what == Constant.EVENT_WHAT_LOCATION_CHANGE) { // 用户位置更新
|
||||||
if (msg.arg1 == LOCATION_FROM.ORIGIN.ordinal()) {
|
if (msg.arg1 == LOCATION_FROM.ORIGIN.ordinal()) {
|
||||||
gpsLocation = (Location) msg.obj;
|
gpsLocation = (TencentLocation) msg.obj;
|
||||||
if (msg.arg1 == mainLocationFrom.ordinal()) { // 如果当前定位方式是主要定位方式
|
if (msg.arg1 == mainLocationFrom.ordinal()) { // 如果当前定位方式是主要定位方式
|
||||||
|
MyLocation location = new MyLocation(gpsLocation.getProvider(), gpsLocation);
|
||||||
|
//设置经纬度以及精度
|
||||||
|
location.setLatitude(gpsLocation.getLatitude());
|
||||||
|
location.setLongitude(gpsLocation.getLongitude());
|
||||||
|
if (gpsLocation.getBearing()!=0) {
|
||||||
|
location.setBearing(gpsLocation.getBearing());
|
||||||
|
} else {
|
||||||
|
location.setBearing((float) gpsLocation.getDirection());
|
||||||
|
}
|
||||||
|
location.setAccuracy(gpsLocation.getAccuracy());
|
||||||
if (locationChangedListenerList!=null) {
|
if (locationChangedListenerList!=null) {
|
||||||
for (LocationSource.OnLocationChangedListener locationChangedListener:locationChangedListenerList) {
|
for (LocationSource.OnLocationChangedListener locationChangedListener:locationChangedListenerList) {
|
||||||
locationChangedListener.onLocationChanged(gpsLocation);
|
locationChangedListener.onLocationChanged(location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.navinfo.outdoor.util;
|
package com.navinfo.outdoor.util;
|
||||||
|
|
||||||
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.tencent.map.geolocation.TencentLocation;
|
import com.tencent.map.geolocation.TencentLocation;
|
||||||
@ -10,11 +11,11 @@ import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TencentLocationObtain {
|
public class TencentLocationObtain {
|
||||||
public static TencentLocation obtainTecentLocation(LatLng latLng) {
|
public static TencentLocation obtainTecentLocation(Location location) {
|
||||||
return new TencentLocation() {
|
return new TencentLocation() {
|
||||||
@Override
|
@Override
|
||||||
public String getProvider() {
|
public String getProvider() {
|
||||||
return "NetWork";
|
return location.getProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -29,22 +30,22 @@ public class TencentLocationObtain {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getLatitude() {
|
public double getLatitude() {
|
||||||
return latLng.getLatitude();
|
return location.getLatitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getLongitude() {
|
public double getLongitude() {
|
||||||
return latLng.getLongitude();
|
return location.getLongitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getAltitude() {
|
public double getAltitude() {
|
||||||
return latLng.getAltitude();
|
return location.getAltitude();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getAccuracy() {
|
public float getAccuracy() {
|
||||||
return 100;
|
return location.getAccuracy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -109,22 +110,22 @@ public class TencentLocationObtain {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getBearing() {
|
public float getBearing() {
|
||||||
return 0;
|
return location.getBearing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getSpeed() {
|
public float getSpeed() {
|
||||||
return 0;
|
return location.getSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTime() {
|
public long getTime() {
|
||||||
return 0;
|
return location.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getElapsedRealtime() {
|
public long getElapsedRealtime() {
|
||||||
return 0;
|
return location.getElapsedRealtimeNanos();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user