[android] 如何判断程序是否在前台运行
2013-07-15 11:41
489 查看
private static boolean isAppOnForeground(String packageName) {
YNoteApplication app = YNoteApplication.getInstance();
ActivityManager activityManager = (ActivityManager) app.getSystemService(app.ACTIVITY_SERVICE);
PowerManager manager = (PowerManager) app.getSystemService(Activity.POWER_SERVICE);
RunningTask Info info = activityManager.getRunningTasks(1).get(0);
ComponentName topComponent = info.topActivity;
if (info.numRunning > 0 && manager.isScreenOn()
&& topComponent != null
&& topComponent.getPackageName().equals(packageName)) {
return true;
}
return false;
}
YNoteApplication app = YNoteApplication.getInstance();
ActivityManager activityManager = (ActivityManager) app.getSystemService(app.ACTIVITY_SERVICE);
PowerManager manager = (PowerManager) app.getSystemService(Activity.POWER_SERVICE);
RunningTask Info info = activityManager.getRunningTasks(1).get(0);
ComponentName topComponent = info.topActivity;
if (info.numRunning > 0 && manager.isScreenOn()
&& topComponent != null
&& topComponent.getPackageName().equals(packageName)) {
return true;
}
return false;
}
相关文章推荐
- android 如何判断程序是否在前台运行
- android 如何判断程序是否在前台运行
- android 如何判断程序是否在前台运行
- android 如何判断程序是否在前台运行
- Android如何判断程序是在前台还是在后台运行
- Android 判断程序是否位于前台,检查当前运行的程序
- Android 判断当前程序是否在前台运行
- 判断Android程序是否在前台运行的两种方法
- android 判断当前程序是否在前台运行
- android 如何判断应用是否在前台运行
- Android 判断程序是否在前台运行
- Android 判断当前程序是否在前台运行
- Android中如何判断本app是否在前台运行
- (4.1.2.6)Android 判断app是否在前台还是在后台运行
- 判断程序是否运行在前台
- Android 判断app是否在前台还是在后台运行
- Android判断App是否在前台运行
- android 判断是否在桌面,当前程序是否在运行
- 如何判断当前程序是否运行在虚拟机内
- 如何判断当前 app 是否在前台运行。