Files
FLYSN/app/src/main/java/com/fuying/sn/base/BaseApplication.java
tongtongstudio d62f7ea042 version:3.4.8
fix:
update:修改主页ui
2026-03-03 16:58:44 +08:00

195 lines
8.0 KiB
Java

package com.fuying.sn.base;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Environment;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
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.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.push.PushManager;
import com.fuying.sn.rlog.LogDBManager;
import com.fuying.sn.service.ControlPanelService;
import com.fuying.sn.service.DownloadService;
import com.fuying.sn.service.GuardService;
import com.fuying.sn.service.ManagerService;
import com.fuying.sn.service.StepService;
import com.fuying.sn.service.main.MainService;
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 com.hjq.toast.Toaster;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.mmkv.MMKV;
public class BaseApplication extends Application {
private static final String TAG = "BaseApplication";
@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();
}
String rootDir = MMKV.initialize(this);
Log.i(TAG, "mmkv root: " + rootDir);
PushManager.init(this);
aliyunPushInit();
Toaster.init(this);
JgyUtils.init(this);
CrashReport.initCrashReport(getApplicationContext(), "e5f026c8d5", false);
CrashReport.setDeviceId(this, Utils.getSerial());
LogDBManager.init(this);
ConnectManager.init(this);
Aria.init(this);
Aria.download(this).resumeAllTask();
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();
startService();
}
private void startService() {
startService(new Intent(this, MainService.class));
startService(new Intent(this, GuardService.class));
startService(new Intent(this, StepService.class));
startService(new Intent(this, DownloadService.class));
startService(new Intent(this, ManagerService.class));
startService(new Intent(this, ControlPanelService.class));
}
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 aliyunPushInit() {
PushServiceFactory.init(this);
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());
String sn = Utils.getSerial();
Log.e(TAG, "AliyunPush: sn=" + sn);
if (TextUtils.isEmpty(sn)) {
return;
}
pushService.bindAccount(sn, new CommonCallback() {
@Override
public void onSuccess(String s) {
Log.e("AliyunPush", "bind account " + sn + " success\n");
}
@Override
public void onFailed(String errorCode, String errorMsg) {
Log.e("AliyunPush", "bind account " + sn + " failed." +
"errorCode: " + errorCode + ", errorMsg:" + errorMsg);
}
});
pushService.addAlias(sn, new CommonCallback() {
@Override
public void onSuccess(String s) {
Log.e("AliyunPush", "add alias " + sn + " success\n");
}
@Override
public void onFailed(String errorCode, String errorMsg) {
Log.e("AliyunPush", "add alias " + sn + " failed." +
"errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n");
}
});
pushService.bindTag(CloudPushService.DEVICE_TARGET, new String[]{BuildConfig.platform}, null, new CommonCallback() {
@Override
public void onSuccess(String s) {
Log.e("AliyunPush", "add tag " + sn + " success\n");
}
@Override
public void onFailed(String errorCode, String errorMsg) {
Log.e("AliyunPush", "add tag " + sn + " failed." +
"errorCode: " + errorCode + ", errorMsg:" + errorMsg + "\n");
}
});
}
@Override
public void onFailed(String errorCode, String errorMessage) {
Log.e("AliyunPush", "init cloudchannel failed -- errorcode:" + errorCode + " -- errorMessage:" + errorMessage);
}
});
}
}