public static boolean isBackground(Context context) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(context.getPackageName())) { /* BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000 PERCEPTIBLE=130 SERVICE=300 ISIBLE=200 */ if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND&& appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE ) { Log.i("zfc_agoo", "trur:" + appProcess.processName); return true; } else { Log.i("zfc_agoo", "trur:" + appProcess.processName); return false; } } } return false; }
android判断是否后台运行
最新推荐文章于 2023-05-06 11:26:49 发布