question

SheikhShuaibAshraf-5498 avatar image
0 Votes"
SheikhShuaibAshraf-5498 asked JarvanZhang-MSFT commented

Usage access permission

I am building an 'App locker' App in which I've displayed all the User Apps and System App in Listview, and I've added a toggle button to this listview, on turning (toggle button) ON/OFF, I want to lock/unlock the app of the phone. And lock is based on Pattern.

Whenever the App, which I locked, there should appear a Pattern Lock for Unlocking the app.

For this I need to grant my App USAGE ACCESS.
How to achieve that

Thanks!

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

Hello,​

Welcome to our Microsoft Q&A platform!

Whenever the App, which I locked, there should appear a Pattern Lock for Unlocking the app. For this I need to grant my App USAGE ACCESS.

The PACKAGE_USAGE_STATS is a dangerous permission which cannot be requested in a pop-up dialog at runtime such as requesting the READ_EXTERNAL_STORAGE permission. We can only guide the user to open the Apps with **strong text**Usage Access setting page.

Here is the code to open the Setting Application page

StartActivity(new Intent(Android.Provider.Settings.ActionUsageAccessSettings));

Best Regards,

Jarvan Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Sir, Thanks for the reply, I Implemented this using dependency in android on button click. But I can't see my app in there in the grant access section in phone. Do I need to do more stuff for achieving the same
Thanks

0 Votes 0 ·
JarvanZhang-MSFT avatar image JarvanZhang-MSFT SheikhShuaibAshraf-5498 ·

@SheikhShuaibAshraf-5498 Please make sure the PACKAGE_USAGE_STATS permisson has been added to AndroidManifest.xml.

<manifest ...>
  ...
  <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
</manifest>
1 Vote 1 ·

Thanks a lot sir.

0 Votes 0 ·

Sir, how to check if the permission is granted
Thanks

0 Votes 0 ·
Show more comments