/**
* 是否应用在前台运行
*/
public static boolean isRunningApp(Context context, String packageName) {
boolean isAppRunning = false;
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(100);
for (ActivityManager.RunningTaskInfo info : list) {
if (info.topActivity.getPackageName().equals(packageName) && info.baseActivity.getPackageName().equals(packageName)) {
isAppRunning = true;
// find it, break
break;
}
}
return isAppRunning;
}
是否应用在前台运行
最新推荐文章于 2021-05-28 10:02:07 发布