Why UsageStats.mLaunchCount is not accessible in I

2019-05-31 01:45发布

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条回答
够拽才男人
2楼-- · 2019-05-31 02:04

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.

查看更多
登录 后发表回答