首页 > 系统 > Android > 正文

Android编程判断当前指定App是否在前台的方法

2020-04-11 11:16:29
字体:
来源:转载
供稿:网友

本文实例讲述了Android编程判断当前指定App是否在前台的方法。分享给大家供大家参考,具体如下:

//在进程中去寻找当前APP的信息,判断是否在前台运行private boolean isAppOnForeground() {ActivityManager activityManager =(ActivityManager) getApplicationContext().getSystemService(  Context.ACTIVITY_SERVICE);String packageName =getApplicationContext().getPackageName();List<RunningAppProcessInfo>appProcesses = activityManager.getRunningAppProcesses();if (appProcesses == null)return false;for (RunningAppProcessInfo appProcess : appProcesses) {if (appProcess.processName.equals(packageName)    && appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {  return true;}}return false;}

希望本文所述对大家Android程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表