Files
XiaoxintongSystemOS/app/src/main/java/com/uiui/aios/base/BaseApplication.java
fanhuitong 059e0e1fee version:
fix:
update:闹钟界面缓存
2022-09-05 20:22:57 +08:00

132 lines
4.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.uiui.aios.base;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.arialyy.aria.core.Aria;
import com.qweather.sdk.view.HeConfig;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import com.uiui.aios.BuildConfig;
import com.uiui.aios.manager.ConnectManager;
import com.uiui.aios.network.NetInterfaceManager;
import com.uiui.aios.service.main.MainService;
import com.uiui.aios.alarm.AlarmUtils;
import com.uiui.aios.manager.AmapManager;
import com.uiui.aios.utils.AppUsedTimeUtils;
import com.uiui.aios.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class BaseApplication extends Application {
private static final String TAG = BaseApplication.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
public static Context context;
@SuppressLint("StaticFieldLeak")
private static BaseApplication instance;
public static Context getAppContext() {
return context;
}
// 单例模式中获取唯一的ExitApplication实例
public static BaseApplication getInstance() {
if (null == instance) {
instance = new BaseApplication();
}
return instance;
}
@Override
public void onCreate() {
super.onCreate();
context = this;
if (!BuildConfig.DEBUG) {
catchException();
}
String rootDir = MMKV.initialize(this);
Log.e(TAG, "mmkv root: " + rootDir);
Aria.init(this);
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
Aria.get(this).getDownloadConfig().setConvertSpeed(true);
tpushInit();
AppUsedTimeUtils.init(this);
AlarmUtils.init(this);
HeConfig.init("HE2206151627491952", "03125bfee8934cf4b640af48e8187c9d");
//切换至开发版服务
HeConfig.switchToDevService();
AmapManager.init(this);
ConnectManager.init(this);
NetInterfaceManager.init(this);
startService(new Intent(this, MainService.class));
}
private void tpushInit() {
XGPushConfig.enableDebug(this, true);
XGPushManager.registerPush(this, new XGIOperateCallback() {
@Override
public void onSuccess(Object data, int flag) {
//token在设备卸载重装的时候有可能会变
Log.e("TPush", "注册成功设备token为" + data);
List<XGPushManager.AccountInfo> accountInfoList = new ArrayList<>();
accountInfoList.add(new XGPushManager.AccountInfo(XGPushManager.AccountType.CUSTOM.getValue(), Utils.getSerial()));
XGPushManager.upsertAccounts(getApplicationContext(), accountInfoList, new XGIOperateCallback() {
@Override
public void onSuccess(Object data, int flag) {
Log.e("TPush", "onSuccess, data:" + data + ", flag:" + flag);
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.e("TPush", "onFail, data:" + data + ", code:" + errCode + ", msg:" + msg);
}
});
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.e("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
}
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();
}
}
}
});
}
}