147 lines
5.4 KiB
Java
147 lines
5.4 KiB
Java
package com.uiuipad.find.base;
|
|
|
|
import android.app.Application;
|
|
import android.os.Handler;
|
|
import android.os.Looper;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
|
|
import com.alibaba.sdk.android.push.CloudPushService;
|
|
import com.alibaba.sdk.android.push.CommonCallback;
|
|
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
|
|
import com.arialyy.aria.core.Aria;
|
|
import com.tencent.bugly.crashreport.CrashReport;
|
|
import com.tencent.mmkv.MMKV;
|
|
import com.uiuipad.find.BuildConfig;
|
|
import com.uiuipad.find.manager.MapManager;
|
|
import com.uiuipad.find.network.NetInterfaceManager;
|
|
import com.uiuipad.find.push.PushManager;
|
|
import com.uiuipad.find.util.Utils;
|
|
|
|
public class BaseApplication extends Application {
|
|
private static final String TAG = BaseApplication.class.getSimpleName();
|
|
|
|
@Override
|
|
public void onCreate() {
|
|
super.onCreate();
|
|
init();
|
|
}
|
|
|
|
private void init() {
|
|
if (!BuildConfig.DEBUG) {
|
|
catchException();
|
|
}
|
|
String rootDir = MMKV.initialize(this);
|
|
Log.i(TAG, "mmkv root: " + rootDir);
|
|
|
|
Aria.init(this);
|
|
NetInterfaceManager.init(this);
|
|
PushManager.init(this);
|
|
MapManager.init(this);
|
|
aliyunPushInit();
|
|
|
|
CrashReport.initCrashReport(getApplicationContext(), "f217a2d1c7", false);
|
|
CrashReport.setDeviceId(this, Utils.getSerial());
|
|
xcrash.XCrash.init(this);
|
|
|
|
}
|
|
|
|
private void catchException() {
|
|
Thread.setDefaultUncaughtExceptionHandler(
|
|
new Thread.UncaughtExceptionHandler() {
|
|
@Override
|
|
public void uncaughtException(Thread t, Throwable e) {
|
|
Log.e("捕获异常子线程:", Thread.currentThread().getName() +
|
|
"在:" + e.getStackTrace()[0].getClassName());
|
|
}
|
|
}
|
|
);
|
|
//下面是新增方法!
|
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
while (true) {
|
|
try {
|
|
Looper.loop(); //会先执行这个方法,然后在执行下面的异常捕获方法!
|
|
} catch (Exception e) {
|
|
Log.e("捕获异常主线程:", Thread.currentThread().getName() +
|
|
"在:" + e.getStackTrace()[0].getClassName());
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void aliyunPushInit() {
|
|
PushServiceFactory.init(this);
|
|
final CloudPushService pushService = PushServiceFactory.getCloudPushService();
|
|
pushService.setLogLevel(CloudPushService.LOG_DEBUG);
|
|
pushService.register(this, new CommonCallback() {
|
|
@Override
|
|
public void onSuccess(String response) {
|
|
Log.e("AliyunPush", "init cloudchannel success");
|
|
Log.e("AliyunPush", "init cloudchannel success " + pushService.getDeviceId());
|
|
String sn = Utils.getSerial();
|
|
Log.e(TAG, "AliyunPush: sn=" + sn);
|
|
if (TextUtils.isEmpty(sn)) {
|
|
return;
|
|
}
|
|
pushService.bindAccount(sn, new CommonCallback() {
|
|
@Override
|
|
public void onSuccess(String s) {
|
|
Log.e("AliyunPush", "bind account " + sn + " success\n");
|
|
}
|
|
|
|
@Override
|
|
public void onFailed(String errorCode, String errorMsg) {
|
|
Log.e("AliyunPush", "bind account " + sn + " failed." +
|
|
"errorCode: " + errorCode + ", errorMsg:" + errorMsg);
|
|
}
|
|
});
|
|
pushService.addAlias(sn, new CommonCallback() {
|
|
@Override
|
|
public void onSuccess(String s) {
|
|
Log.e("AliyunPush", "add alias " + sn + " success\n");
|
|
}
|
|
|
|
@Override
|
|
public void onFailed(String errorCode, String errorMsg) {
|
|
Log.e("AliyunPush", "add alias " + sn + " failed." +
|
|
"errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n");
|
|
}
|
|
});
|
|
String[] tag = new String[]{BuildConfig.platform};
|
|
pushService.bindTag(CloudPushService.DEVICE_TARGET, tag, null, new CommonCallback() {
|
|
@Override
|
|
public void onSuccess(String s) {
|
|
Log.e("AliyunPush", "bind tag " + tag + " success");
|
|
}
|
|
|
|
@Override
|
|
public void onFailed(String errorCode, String errorMsg) {
|
|
Log.e("AliyunPush", "bind tag " + tag + " failed." +
|
|
"errorCode: " + errorCode + ", errorMsg:" + errorMsg);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void onFailed(String errorCode, String errorMessage) {
|
|
Log.e("AliyunPush", "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage);
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
@Override
|
|
public void onLowMemory() {
|
|
super.onLowMemory();
|
|
}
|
|
|
|
@Override
|
|
public void onTrimMemory(int level) {
|
|
super.onTrimMemory(level);
|
|
}
|
|
}
|