Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use getSystemService("usagestats") Android Studio

Tags:

android

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?

like image 512
Abhishek Avatar asked Dec 21 '14 18:12

Abhishek


1 Answers

Must be some kind of bug in Android Studio. You can disable inspection by adding:

//noinspection ResourceType
UsageStatsManager usageStatsManager=(UsageStatsManager)context.getSystemService("usagestats");
like image 91
myfknoll Avatar answered Sep 21 '22 06:09

myfknoll