-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
判断App是否在前台,获取前台App的包名(仅支持系统App),同时对不同版本做兼容 #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
这个也可以判断其他应用,所以不需要其他方法了,你的getPackegeName3和4我root测试都是返回null |
你这种就是 getPackegeName2,此方法在 API 21 之前只有在自己的 APP 在前台时可以抓取到其包名,其他 APP 在前台时 |
我今天测试了,stackoverflow上也说到不需要 系统应用,只需要添加Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);这个选项应用打开,在加上那个权限即可,下面是我的完整代码。
|
我刚刚在 |
恩,有些厂商给阉割了,所以加了if (list.size() > 0)这个判断,我MIUI8和原生6.0测的, |
RunningAppProcessInfo
进可判断自己应用本身是否在前台,二不能判断某个 APP 是否在前台;RunningTaskInfo
,需添加android.permission.GET_TASKS
权限RunningAppProcessInfo
UsageStatsManager
,需添加android.permission.PACKAGE_USAGE_STATS
权限