user1406716
user1406716

Reputation: 9705

Error in Manifest.xml when adding PACKAGE_USAGE_STATS [Android Lollipop]

I am trying to use "android.permission.PACKAGE_USAGE_STATS" in my app. Here it says that NOTE: This API requires the permission android.permission.PACKAGE_USAGE_STATS, which is a system-level permission and will not be granted to third-party apps. However, declaring the permission implies intention to use the API and the user of the device can grant permission through the Settings application.

enter image description here

It seems that I will need the user to explicitly give my app the permission to give access to the access the usage stats.

In addition, I used the intent code below to open the screen to allow user to give access to my app, but my app is not in the list. Code I used:

Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);

When *startActivity(intent)' is fired (or going to *Settings>Security>Apps with Usage Access), a blank screen below pops up, my app is not part of it. enter image description here

Bottom line question is -- How to use UsageStatsManager in Android Lollipop? Anyone tried it?

Upvotes: 3

Views: 6067

Answers (3)

Loebre
Loebre

Reputation: 672

This is what worked for me.

<uses-permission xmlns:tools="http://schemas.android.com/tools"
    android:name="android.permission.PACKAGE_USAGE_STATS"
    tools:ignore="ProtectedPermissions" />

Upvotes: 11

android developer
android developer

Reputation: 115980

You can simply make this on the manifest, ignoring just this permission error:

<uses-permission
    android:name="android.permission.PACKAGE_USAGE_STATS"
    tools:ignore="ProtectedPermissions"/>

Upvotes: 8

nandeesh
nandeesh

Reputation: 24820

The AndroidManifest.xml error can be fixed by disabling lint errors. Specifically

Security - SignatureorSystemPermissions 

I guess after that the settings app will show your app.

Upvotes: 1

Related Questions