I am trying to use UsageStatsManager
with reference to this SO question. My line of code is
UsageStatsManager usageStatsManager=(UsageStatsManager)context.getSystemService("usagestats");
I also tried to use
UsageStatsManager usageStatsManager=(UsageStatsManager)context.getSystemService(Context.USAGE_STATS_SERVICE);
Regardless of what I use Android Studio says, "Must be one of: Context.POWER_SERVICE, Context.WINDOW_SERVICE..."
After a lot of research I came to know that Context.USAGE_STATS_SERVICE
is hidden, so I must add the permission
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
But still, the results are same. What am I missing?
Must be some kind of bug in Android Studio. You can disable inspection by adding:
//noinspection ResourceType
UsageStatsManager usageStatsManager=(UsageStatsManager)context.getSystemService("usagestats");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With