/**
* 返回app运行状态
* 1:程序在前台运行
* 2:程序在后台运行
* 3:程序未启动
* 注意:需要配置权限<uses-permission android:name="android.permission.GET_TASKS" />
*/
public int getAppSatus(Context context, String pageName) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(20);
//判断程序是否在栈顶
if (list.get(0).topActivity.getPackageName().equals(pageName)) {
return 1;
} else {
//判断程序是否在栈里
for (ActivityManager.RunningTaskInfo info : list) {
if (info.topActivity.getPackageName().equals(pageName)) {
return 2;
}
}
return 3;//栈里找不到,返回3
}
}
info.topActivity.getClassName().equals(activityName)
KeyguardManager mKeyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
// keyguard on
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/pengkv/article/details/48769633