river-lucky-driver/app/src/main/java/com/arpa/hndahesudintocctmsdriver/App.java
2023-10-07 08:25:39 +08:00

229 lines
11 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.arpa.hndahesudintocctmsdriver;
import android.app.ActivityManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Environment;
import android.util.Log;
import androidx.core.app.ActivityCompat;
import com.alct.mdp.MDPLocationCollectionManager;
import com.arpa.hndahesudintocctmsdriver.report.JTTProcess;
import com.arpa.hndahesudintocctmsdriver.request.net.Api;
import com.arpa.hndahesudintocctmsdriver.ui.MainActivity;
import com.arpa.hndahesudintocctmsdriver.util.BillLocationUtils;
import com.arpa.hndahesudintocctmsdriver.util.SPUtils;
import com.arpa.hndahesudintocctmsdriver.util.location.LocationGDUtil;
import com.dahe.mylibrary.CommonBaseLibrary;
import com.dahe.mylibrary.utils.TimeUtil;
import com.dahe.mylibrary.utils.ToastUtils;
import com.esign.esignsdk.EsignSdk;
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
import com.gyf.cactus.Cactus;
import com.gyf.cactus.callback.CactusBackgroundCallback;
import com.gyf.cactus.callback.CactusCallback;
import com.permissionx.guolindev.PermissionX;
import com.tencent.bugly.crashreport.CrashReport;
import com.umeng.commonsdk.UMConfigure;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;
import cn.jiguang.verifysdk.api.JVerificationInterface;
public class App extends Application implements CactusCallback {
// String key = "f9d35b1133cff1f6e3960c89b249e03f";
String key = "19ac0aa74338e487e45057faf7212401";
String license = "HF41uGxM/1i3CtW98DimoA97BlNTAnQ+DiEAihYmZ2jR1jqC4be253joEJbOJgFDIzp5aIoeuXSWWHFaDVfaHL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neMx+TsidnQ0ZG29aqdcLBRsvi26BYJJCA8+0WXjT+73RhS8g97Rfb6h0/W//5Az8UNZ6dp6XvUi2EJXQRhY5hkHiuwWT2W1ik+6wiiURkkrBACKbO1kmZWbVpRIe3Y3pcr3Q/V+oAcyPHRXCxu+JIe/j40/epuRrCyf8yvKsZ2Dnkl4QQmlwNqlW1F/arS+19G6zOG+6VKwtbI01A1R9SU1TYOA5UL/Qpo6Gyi3Ec3/irgQlzkq1rZrOIS4oo6tghul/zcG8rjno3luqHYwIZf8vAVfpwBesIVcANCOIuTRPU3A8vdmUoK/twGIchPapmjlAzLhjZ4KoAbNeMsWu3sN6kF44xofLMghos2X8OtvUA9CMD37v2FpYoM75qavyoivsBAbb6mG0p5TmkZ37BxfaGGP6SYrCa9ygQ==";
public final static int APP_STATUS_KILLED = 0; // 表示应用是被杀死后在启动的
public final static int APP_STATUS_NORMAL = 1; // 表示应用时正常的启动流程
public static int APP_STATUS = APP_STATUS_KILLED; // 记录App的启动状态
private Context con;
public static App mApplication = null;
@Override
public void onCreate() {
super.onCreate();
mApplication = this;
con = getBaseContext();
CommonBaseLibrary.getInstance().init(this, Api.BASE_URL);
CrashReport.initCrashReport(getApplicationContext(), "0fa55ffad8", false);
String state = SPUtil.getSP(con, "state_data", "authorization_state");
if ("1".equals(state)) {
try {
Context context = getApplicationContext();
Resources res = getResources();
Configuration config = new Configuration();
config.setToDefaults();
res.updateConfiguration(config, res.getDisplayMetrics());
//安联初始化
if (context.getPackageName().equals(getCurrentProcessName(context))) {
//Log.e("--使用的测试环境--",BuildConfig.OPEN_API_URL);
MDPLocationCollectionManager.initialize(this, BuildConfig.OPEN_AL_URL);
}
//在使用SDK各组件之前初始化context信息传入ApplicationContext
// 路由初始化
JVerificationInterface.setDebugMode(true);
JVerificationInterface.init(this, 5000, (code, msg) -> Log.d("tag", "code = " + code + " msg = " + msg));
//友盟
//设置非debug版本开启
if (!isDebugVersion(con)) {
youmenginit();
}
EsignSdk.getInstance().init(key, license);
JTTProcess.init(this);
//QupaiHttpFinal.getInstance().initOkHttpFinal();
} catch (Exception e) {
Log.e("-error-", "初始化失败sss");
}
}
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
Cactus.getInstance()
.isDebug(true)
.setTitle("好运司机")
.setContent("您的接单助手!")
.setChannelId("gld")
.setChannelName("好运司机")
.setServiceId(Integer.MAX_VALUE)
//可选,设置通知栏点击事件
.setPendingIntent(pendingIntent)
.setBackgroundMusicEnabled(true)//可选,退到后台是否可以播放音乐
.setMusicId(R.raw.main) //可选,设置音乐
// .setPendingIntent(pendingIntent)//可选,设置通知栏点击事件
// .addCallback(new CactusCallback())//可选,运行时回调
.setCrashRestartUIEnabled(true) //可选设置奔溃可以重启google原生rom android 10以下可以正常重启
.setCrashRestartUIEnabled(true)//可选设置奔溃可以重启google原生rom android 10以下可以正常重启
.setSmallIcon(R.drawable.diver_logo)
.addCallback(this)
.addBackgroundCallback(new CactusBackgroundCallback() {
@Override
public void onBackground(boolean b) {
if (b) {
getBillLocation();
}
}
})
.register(this);
}
public static App getApp() {
return mApplication;
}
public void youmenginit() {
//设置LOG开关默认为false
UMConfigure.setLogEnabled(true);
//友盟预初始化
UMConfigure.preInit(getApplicationContext(), "60fbfe87ff4d74541c81e01a", "Umeng");
/**
* 打开app首次隐私协议授权以及sdk初始化判断逻辑请查看SplashTestActivity
*/
//判断是否同意隐私协议uminit为1时为已经同意直接初始化umsdk
// if(SPUtil.getSP(getAppContext(),"umeng","uminit").equals("1")){
//友盟正式初始化
UMConfigure.init(getApplicationContext(), UMConfigure.DEVICE_TYPE_PHONE, "");
}
private void getBillLocation() {
BillLocationUtils.getInstance().getBillLocation(con);
}
private static String getCurrentProcessName(Context context) {
String currentProcessName = "";
int pid = android.os.Process.myPid();
ActivityManager mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
if (mActivityManager.getRunningAppProcesses() != null && mActivityManager.getRunningAppProcesses().size() > 0) {
for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager.getRunningAppProcesses()) {
if (appProcess.pid == pid) {
currentProcessName = appProcess.processName;
}
}
}
return currentProcessName;
}
private static boolean isDebugVersion(Context context) {
try {
ApplicationInfo info = context.getApplicationInfo();
return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public void doWork(int i) {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
FileOutputStream fos = null;
try {
String nowString = TimeUtil.getNowString(TimeUtil.DEFAULT_FORMAT);
String content = i + "当前时间:"+nowString;
String fileName = "location" + ".txt";
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
//获取文件输出路径
String path = Environment.getExternalStorageDirectory()
+ "/crashinfo2/";
//创建文件夹和文件
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
// File file = new File(path + fileName);
// if (!file.exists())
// file.createNewFile();
//创建输出流
fos = new FileOutputStream(path + fileName,true);
File file = new File(path + fileName);
if (file.exists()){
fos.write('\r');
}
//向文件中写出数据
fos.write(content.toString().getBytes());
}
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}, 100, 1000);
}
@Override
public void onStop() {
}
}