Can't Get Write_Settings Permission

Can't get WRITE_SETTINGS permission

To use WRITE_SETTINGS, based on the docs:

  1. Have the <uses-permission> element in the manifest as normal.

  2. Call Settings.System.canWrite() to see if you are eligible to write out settings.

  3. If canWrite() returns false, start up the ACTION_MANAGE_WRITE_SETTINGS activity so the user can agree there to allow your app to actually write to settings.

In other words, writing to settings is now a double-opt-in (agree to install, agree separately in Settings to allow), akin to device admin APIs, accessibility services, etc.

Also note that I have not tried using these yet — this is based on research that I did yesterday on Android 6.0 changes.

Is android.permission.WRITE_SETTINGS only granted to system apps?

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.

The best way to check for write_settings permission

Yes, you can.

These two verifications do practically the same thing, except that you need the Android Support dependency in order to use ContextCompat, whereas Settings.System is part of the default Android SDK. Note that Context class can check for permissions too.

By the way, electing one way as the best way to check for permissions is rather opinion-based, and it's not something the stackoverflow community fancies too much. You should compare the possibilities and choose the one that fits you best.

but this way is very bad 'cause have to check every time what is Android version. :(

You'll get used to it.



Related Topics



Leave a reply



Submit