Why UsageStats.mLaunchCount is not accessible in IDE?

断了今生、忘了曾经 提交于 2020-01-03 03:17:04

问题


I have all permissions in place and can get the list of apps, and their usage stats as a list of UsageStats instances. UsageStats has a public field called mLaunchCount, added on API 22 (based on git history of the file). Now I want to access this if the phone is running API 22+, but when I try to use it, the IDE complains Cannot resolve symbol mLaunchCount. If I try to access it via reflection, it works.

So basically this does not compile:

Log.d("test", "Count: " + usageStat.mLaunchCount);

While this does:

Field mLaunchCount = UsageStats.class.getDeclaredField("mLaunchCount");
int launchCount = (Integer)mLaunchCount.get(usageStat);
Log.d("Test", "Count: " + launchCount);

Any idea what's happening?

Thanks


回答1:


Because mLaunchCount is not part of the Android SDK. In the source code, it is marked with the @hide annotation, used for things that are public for Java reasons but are not part of the SDK.



来源:https://stackoverflow.com/questions/33793157/why-usagestats-mlaunchcount-is-not-accessible-in-ide

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