| | |
| | | |
| | | import android.app.Activity; |
| | | import android.app.ActivityManager; |
| | | import android.app.AlarmManager; |
| | | import android.app.Application; |
| | | import android.app.PendingIntent; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.res.Configuration; |
| | |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.ConstantManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.enums.LogoutType; |
| | | import com.hdl.photovoltaic.enums.LowerTagType; |
| | | import com.hdl.photovoltaic.enums.NetworkType; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlAccountLogic; |
| | | import com.hdl.photovoltaic.other.HdlDeviceLogic; |
| | | import com.hdl.photovoltaic.other.HdlFileLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | |
| | | @Override |
| | | public void onCreate() { |
| | | super.onCreate(); |
| | | Log.d("=======", "11111111"); |
| | | |
| | | // // 获取当前进程的PID |
| | | // String processMessage= "进程ID:"+Process.myPid()+" 进程名:"+RuningAcitvityUtil.getAppName(getBaseContext()); |
| | | // String processMessage = "进程Uid:" + Process.myUid() + "进程ID:" + Process.myPid() + " 进程名:" + RuningAcitvityUtil.getAppName(getBaseContext()); |
| | | // Log.d("=======", processMessage); |
| | | // Log.d(TAG, processMessage); |
| | | // if (RuningAcitvityUtil.getAppName(getBaseContext()).contains(":")) { |
| | | // //非原生进程,用初始化后面的 |
| | |
| | | HDLLinkPMUser.getInstance().setOnReloginListener(new IOnReloginListener() { |
| | | @Override |
| | | public void onReLogin(int type) { |
| | | |
| | | if (100 == type) { |
| | | if (type == LogoutType.ServerSwitchingLogout.getValue()) { |
| | | new Handler().postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //切换服务器地址用的 |
| | | UserConfigManage.getInstance().setOnlineServer(!UserConfigManage.getInstance().isOnlineServer()); |
| | | UserConfigManage.getInstance().Save(); |
| | | restartApp(mHDLApp); |
| | | } |
| | | }, 500); |
| | | } else if (type == LogoutType.AbnormalLogout.getValue()) { |
| | | //异常情况-强制重启应用 |
| | | new Handler().postDelayed(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | restartApp(mHDLApp); |
| | | } |
| | | }, 500); |
| | |
| | | }); |
| | | |
| | | } |
| | | |
| | | public void test(Context context) { |
| | | // new Handler().postDelayed(() -> { |
| | | // // 1. 设置延迟重启 |
| | | // Intent restartIntent = new Intent(context, StartActivity.class); |
| | | // restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| | | // |
| | | // PendingIntent pendingIntent = PendingIntent.getActivity( |
| | | // context, 0, restartIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT |
| | | // ); |
| | | // |
| | | // AlarmManager am1 = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); |
| | | // am1.set(AlarmManager.RTC, System.currentTimeMillis() + 300, pendingIntent); |
| | | // |
| | | // int myUid = android.os.Process.myUid(); |
| | | // ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
| | | // String packageName = context.getPackageName(); |
| | | // |
| | | // for (ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) { |
| | | // if (proc.uid == myUid && proc.processName.startsWith(packageName)) { |
| | | // if (proc.pid != android.os.Process.myPid()) { |
| | | // try { |
| | | // android.os.Process.killProcess(proc.pid); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // // 3. 退出当前进程 |
| | | // android.os.Process.killProcess(android.os.Process.myPid()); |
| | | // }, 500); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 初始化UniMPSDK 小程序SDK |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 重启app |
| | | */ |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 关掉app所有进程 |
| | | * |
| | | * @param context 上下文 |
| | | */ |
| | | private void killAppProcess(Context context) { |
| | | // AppManagerUtils.getAppManager().finishAllActivity(); |
| | | try { |
| | |
| | | List<android.app.ActivityManager.RunningAppProcessInfo> processInfos = manager.getRunningAppProcesses(); |
| | | // 先杀掉相关进程,最后再杀掉主进程 |
| | | for (android.app.ActivityManager.RunningAppProcessInfo runningAppProcessInfo : processInfos) { |
| | | if (runningAppProcessInfo.pid != android.os.Process.myPid()) { |
| | | if ((runningAppProcessInfo.uid == android.os.Process.myUid()) && (runningAppProcessInfo.pid != android.os.Process.myPid())) { |
| | | try { |
| | | android.os.Process.killProcess(runningAppProcessInfo.pid); |
| | | } catch (Exception e) { |