码迷,mamicode.com
首页 > 移动开发 > 详细

Android之判断当前指定App是否在前台

时间:2015-04-19 10:04:46      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

直接上代码,不多说

技术分享
//在进程中去寻找当前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之判断当前指定App是否在前台

标签:

原文地址:http://www.cnblogs.com/ad716/p/4438625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!