version
fix: update:修改包名
This commit is contained in:
155
app/src/main/java/com/xwad/os/base/BaseApplication.java
Normal file
155
app/src/main/java/com/xwad/os/base/BaseApplication.java
Normal file
@@ -0,0 +1,155 @@
|
||||
package com.xwad.os.base;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
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.arialyy.aria.core.Aria;
|
||||
import com.hjq.toast.Toaster;
|
||||
import com.tencent.bugly.crashreport.CrashReport;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.xwad.os.BuildConfig;
|
||||
import com.xwad.os.alarm.AlarmUtils;
|
||||
import com.xwad.os.manager.AmapManager;
|
||||
import com.xwad.os.manager.AppManager;
|
||||
import com.xwad.os.manager.ConnectManager;
|
||||
import com.xwad.os.manager.RemoteManager;
|
||||
import com.xwad.os.network.NetInterfaceManager;
|
||||
import com.xwad.os.push.PushManager;
|
||||
import com.xwad.os.receiver.APKinstallReceiver;
|
||||
import com.xwad.os.utils.ActivationUtil;
|
||||
import com.xwad.os.utils.AppUsedTimeUtils;
|
||||
import com.xwad.os.utils.LenovoCsdkUtil;
|
||||
import com.xwad.os.utils.OpenApkUtils;
|
||||
import com.xwad.os.utils.SystemUtils;
|
||||
|
||||
public class BaseApplication extends Application {
|
||||
private static final String TAG = "BaseApplication";
|
||||
|
||||
/**
|
||||
* ViewModel中因为经常旋转导致弱引用为空
|
||||
*/
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static BaseApplication sInstance;
|
||||
|
||||
public static BaseApplication getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.e(TAG, "onCreate: ");
|
||||
sInstance = this;
|
||||
|
||||
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) {
|
||||
catchException();
|
||||
}
|
||||
if (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) {
|
||||
String rootDir = MMKV.initialize(this);
|
||||
Log.e(TAG, "mmkv root: " + rootDir);
|
||||
|
||||
ActivationUtil.init(this);
|
||||
LenovoCsdkUtil.init(this);
|
||||
|
||||
CrashReport.initCrashReport(getApplicationContext(), "d1cd982951", false);
|
||||
CrashReport.setDeviceId(BaseApplication.this, LenovoCsdkUtil.getInstance().getSerial());
|
||||
|
||||
// 初始化 Toast 框架
|
||||
Toaster.init(this);
|
||||
AmapManager.init(this);
|
||||
AppManager.init(this);
|
||||
PushManager.init(this);
|
||||
RemoteManager.init(this);
|
||||
|
||||
AlarmUtils.init(this);
|
||||
AppUsedTimeUtils.init(this);
|
||||
OpenApkUtils.init(this);
|
||||
ConnectManager.init(this);
|
||||
NetInterfaceManager.init(this);
|
||||
// startService(new Intent(this, MainService.class));
|
||||
registAppReceive();
|
||||
|
||||
Aria.init(this);
|
||||
// Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
// Aria.get(this).getDownloadConfig().setConvertSpeed(true);
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user