Files
Xuewang365OSLenovo/app/src/main/java/com/uiui/zyos/base/BaseApplication.java
Fanhuitong 3346ffca88 version:1.3.5
fix:
update:增加学习资源下载,修复退出桌面再进入卡顿,增加语音助手
2023-04-23 11:08:44 +08:00

150 lines
5.6 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.zyos.base;
import android.app.Application;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Looper;
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.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.mmkv.MMKV;
import com.uiui.zyos.BuildConfig;
import com.uiui.zyos.alarm.AlarmUtils;
import com.uiui.zyos.manager.ConnectManager;
import com.uiui.zyos.manager.RemoteManager;
import com.uiui.zyos.network.NetInterfaceManager;
import com.uiui.zyos.push.PushManager;
import com.uiui.zyos.receiver.APKinstallReceiver;
import com.uiui.zyos.service.main.MainService;
import com.uiui.zyos.utils.AppUsedTimeUtils;
import com.uiui.zyos.utils.OpenApkUtils;
import com.uiui.zyos.utils.SystemUtils;
import com.uiui.zyos.utils.Utils;
import java.util.ArrayList;
import java.util.List;
public class BaseApplication extends Application {
private static final String TAG = BaseApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
if (!BuildConfig.DEBUG) {
catchException();
}
init();
}
private void init() {
if (BuildConfig.DEBUG) {
}
if (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) {
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);
PushManager.init(this);
tpushInit();
aliyunPushInit();
RemoteManager.init(this);
RemoteManager.setListener(new RemoteManager.ConnectedListener() {
@Override
public void onConnected() {
RemoteManager.getInstance().aliyunPushInit();
RemoteManager.getInstance().tpushInit();
}
});
AlarmUtils.init(this);
AppUsedTimeUtils.init(this);
OpenApkUtils.init(this);
ConnectManager.init(this);
NetInterfaceManager.init(this);
// startService(new Intent(this, MainService.class));
registAppReceive();
}
}
private APKinstallReceiver apKinstallReceiver;
private void registAppReceive() {
if (null == apKinstallReceiver) {
apKinstallReceiver = new APKinstallReceiver();
}
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
registerReceiver(apKinstallReceiver, filter);
}
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);
}
@Override
public void onFail(Object data, int errCode, String msg) {
Log.e("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
}
});
}
public 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());
}
@Override
public void onFailed(String errorCode, String errorMessage) {
Log.e("AliyunPush", "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage);
}
});
}
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();
}
}
}
});
}
}