**Java.Lang.SecurityException:** was not granted this permission: android.permission.WRITE_SETTINGS.'

Ahmed Wassim BEN SALEM (ENISo) 241 Reputation points
2021-04-08T12:46:47.027+00:00

Hello guys , so i am trying to make my device screen go to sleep with this code in android :

Android.Provider.Settings.System.PutInt(((Activity)Forms.Context).ContentResolver,
Android.Provider.Settings.System.ScreenOffTimeout, 1000);

I added this permission :
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

When I tired to run the application , i get that Exception ..
does anyone knows how to allow /get granted the WRITE_SETTINGS Permission
Appreciate your help guys ..

Developer technologies | .NET | Xamarin
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-04-08T13:51:43.503+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    As stated by user passsy in the stackoverflow question provided by Brian, android.permission.WRITE_SETTINGS has a android:protectionLevel of "signature", which makes the permission unavailable for use in user applications since API level 23.

    See https://developer.android.com/guide/topics/manifest/permission-element#plevel for the description of protection levels for permissions.

    Best Regards,

    Leon Lu


    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.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.