Request permission on PACKAGE_USAGE_STATS

前端 未结 1 1070
生来不讨喜
生来不讨喜 2021-01-13 03:29

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:

//         


        
1条回答
  •  既然无缘
    2021-01-13 03:38

    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 UsageStatsManager documentation:

    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.

    0 讨论(0)
提交回复
热议问题