Is android.permission.PACKAGE_USAGE_STATS Only for System Apps?

强颜欢笑 提交于 2019-12-24 11:35:02

问题


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)

Seems to work for:

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

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;

And also

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

回答1:


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.

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.



来源:https://stackoverflow.com/questions/32774571/is-android-permission-package-usage-stats-only-for-system-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!