Files
Xuewang365OSLenovo/app/src/main/java/com/uiui/zyos/base/BaseApplication.java
Fanhuitong a232b6919d version:1.7.1
fix:
update:更换图标,添加应用页面
2024-01-06 16:07:30 +08:00

147 lines
5.3 KiB
Java

package com.uiui.zyos.base;
import android.app.Application;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Debug;
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.noonesdk.PushServiceFactory;
import com.arialyy.aria.core.Aria;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.mmkv.MMKV;
import com.uiui.zyos.BuildConfig;
import com.uiui.zyos.alarm.AlarmUtils;
import com.uiui.zyos.manager.AppManager;
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.utils.AppUsedTimeUtils;
import com.uiui.zyos.utils.OpenApkUtils;
import com.uiui.zyos.utils.SystemUtils;
public class BaseApplication extends Application {
private static final String TAG = BaseApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
Log.e(TAG, "onCreate: ");
if (!BuildConfig.DEBUG) {
// catchException();
}
// 在开始分析的地方调用,传入路径
// 如果是放到外部路径,需要添加权限
// 默认存储在/sdcard/Android/data/packagename/files
// Debug.startMethodTracing("App" + System.currentTimeMillis());
init();
// 在结束的地方调用
// Debug.stopMethodTracing();
}
private void init() {
Log.e(TAG, "init: ");
if (BuildConfig.DEBUG) {
}
if (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) {
String rootDir = MMKV.initialize(this);
Log.e(TAG, "mmkv root: " + rootDir);
AppManager.init(this);
PushManager.init(this);
RemoteManager.init(this);
RemoteManager.setListener(new RemoteManager.ConnectedListener() {
@Override
public void onConnected() {
RemoteManager.getInstance().aliyunPushInit();
}
});
AlarmUtils.init(this);
AppUsedTimeUtils.init(this);
OpenApkUtils.init(this);
ConnectManager.init(this);
NetInterfaceManager.init(this);
// startService(new Intent(this, MainService.class));
registAppReceive();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
slowInit();
}
}, 1234);
}
}
private void slowInit() {
Log.e(TAG, "slowInit: ");
Aria.init(this);
// Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
// Aria.get(this).getDownloadConfig().setConvertSpeed(true);
CrashReport.initCrashReport(getApplicationContext(), "d1cd982951", false);
aliyunPushInit();
}
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 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 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();
}
}
}
});
}
}