Skip to content Skip to sidebar Skip to footer

Request Permission On Package_usage_stats

I want to check wheter the user have granted permission for my application to use PACKAGE_USAGE_STATS. What I am currently doing is this: // Control that the required permissions i

Solution 1:

Unfortunately you can't request the PACKAGE_USAGE_STATS at runtime like you do with a dangerous permission. The user need to manually grant the permission through the Settings application as explained in the UsageStatsManagerdocumentation:

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.

You can directly open the Apps with usage access activity with this code:

startActivity(new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));

Here you can find an example of a basic app that shows how to use App usage statistics API.

Post a Comment for "Request Permission On Package_usage_stats"