android.permission.PACKAGE_USAGE_STATS仅适用于系统应用程序吗? [英] Is android.permission.PACKAGE_USAGE_STATS Only for System Apps?

查看:1477
本文介绍了android.permission.PACKAGE_USAGE_STATS仅适用于系统应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式访问用户统计信息:

I am accessing user stats in the following ways:

 UsageStatsManager userStatsMgr = (UsageStatsManager)getSystemService("usagestats"); 

 List<UsageStats> userStats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, timeStamp - 1000*200, timeStamp)

似乎适用于:

 android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP

但是我不确定它是否将继续在较新的SDK上运行?使用此权限时,我会看到一些警告,但这些警告并不具体.所以我想知道这些限制到底是什么?

But I am not sure whether it will continue to work on newer SDK? I see some warning while using this permission, but those were not specific. So I am wondering what exactly these restrictions are?

 ActivityManager mgr =  (ActivityManager)ctx.getSystemService(Context.ACTIVITY_SERVICE);
                            List<ActivityManager.RunningAppProcessInfo>   
     processes = manager.getRunningAppProcesses();
                            app=processes.get(0).processName;

还有

      ActivityManager actMgr = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
                    actMgr.killBackgroundProcesses(process);

推荐答案

android.permission.PACKAGE_USAGE_STATS只能由系统活动授予,并且该活动可能并不存在于所有设备上.已知已从至少某些设备上将其删除的制造商包括三星和LG.

android.permission.PACKAGE_USAGE_STATS can only be granted by a system activity, and the activity may not be present on all devices. Manufacturers that are known to have removed it from at least some of their devices include Samsung and LG.

启动系统活动的意图动作是Settings.ACTION_USAGE_ACCESS_SETTINGS.检查 Intent#resolveActivity(...) 在尝试启动它之前返回非null值.

The intent action to launch the system activity is Settings.ACTION_USAGE_ACCESS_SETTINGS. Check that Intent#resolveActivity(...) returns a non-null value before attempting to launch it.

这篇关于android.permission.PACKAGE_USAGE_STATS仅适用于系统应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆