更换包名
This commit is contained in:
140
app/src/main/java/com/fuying/sn/base/BaseApplication.java
Normal file
140
app/src/main/java/com/fuying/sn/base/BaseApplication.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package com.fuying.sn.base;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
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.fuying.sn.BuildConfig;
|
||||
import com.fuying.sn.desktop.RunningAppManager;
|
||||
import com.fuying.sn.desktop.TimeControlManager;
|
||||
import com.fuying.sn.manager.AmapManager;
|
||||
import com.fuying.sn.manager.ConnectManager;
|
||||
import com.fuying.sn.manager.ControlManager;
|
||||
import com.fuying.sn.manager.DeviceManager;
|
||||
import com.fuying.sn.network.NetInterfaceManager;
|
||||
import com.fuying.sn.rlog.LogDBManager;
|
||||
import com.fuying.sn.utils.AppUsedTimeUtils;
|
||||
import com.fuying.sn.utils.JGYUtils;
|
||||
import com.fuying.sn.utils.SystemUtils;
|
||||
import com.fuying.sn.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 (SystemUtils.isMainProcessName(this, android.os.Process.myPid())) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
// ApkUtils.openApp(this, "com.android.settings");
|
||||
//静音
|
||||
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
|
||||
int ringMax = audioManager.getStreamMinVolumeInt(AudioManager.STREAM_RING);
|
||||
audioManager.setStreamVolume(AudioManager.STREAM_RING, ringMax, 0);
|
||||
int musicMax = audioManager.getStreamMinVolumeInt(AudioManager.STREAM_MUSIC);
|
||||
int voiceMax = audioManager.getStreamMinVolumeInt(AudioManager.STREAM_VOICE_CALL);
|
||||
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, voiceMax, 0);
|
||||
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicMax, 0); //音乐音量
|
||||
Log.e(TAG, "debugTest: " + getExternalCacheDir());
|
||||
Log.e(TAG, "debugTest: " + getExternalFilesDir("cache"));
|
||||
Log.e(TAG, "debugTest: " + getCacheDir());
|
||||
Log.e(TAG, "debugTest: " + Environment.getExternalStorageDirectory());
|
||||
}
|
||||
utilsInint();
|
||||
}
|
||||
}
|
||||
|
||||
private void utilsInint() {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
catchException();
|
||||
}
|
||||
tPushInit();
|
||||
String rootDir = MMKV.initialize(this);
|
||||
Log.i(TAG, "mmkv root: " + rootDir);
|
||||
|
||||
LogDBManager.init(this);
|
||||
ConnectManager.init(this);
|
||||
Aria.init(this);
|
||||
Aria.download(this).resumeAllTask();
|
||||
JGYUtils.init(this);
|
||||
RunningAppManager.init(this);
|
||||
TimeControlManager.init(this);
|
||||
ControlManager.init(this);
|
||||
// ControlPanelManager.init(this);
|
||||
DeviceManager.init(this);
|
||||
AmapManager.init(this);
|
||||
NetInterfaceManager.init(this);
|
||||
AppUsedTimeUtils.init(this);
|
||||
JGYUtils.hookWebView();
|
||||
}
|
||||
|
||||
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 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()));
|
||||
accountInfoList.add(new XGPushManager.AccountInfo(XGPushManager.AccountType.CUSTOM.getValue(), Utils.getIMEI(getApplicationContext())));
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user