How To Grant Write Settings Permission In Android

When you write an android app, you sometimes may need to change system settings. For example, change the android device screen brightness. But such action needs your app to have android.permission.WRITE_SETTINGS permission, otherwise you may encounter the exception with the message java.lang.SecurityException: com.dev2qa.example was not granted this permission: android.permission.WRITE_SETTINGS.

1. Add Android WRITE_SETTINGS Permission Steps.

  1. Add below <uses-permission> XML tag in AndroidManifest.xml file.
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
  2. Call Settings.System.canWrite(context) to check whether your android app can write settings in the current Android device.
    boolean settingsCanWrite = Settings.System.canWrite(context);
  3. If the above code return false which means your app does not has the write settings permission, then you need to start activity Settings.ACTION_MANAGE_WRITE_SETTINGS to let users change the permission manually.
  4. After the permission has been changed, you can type the back menu to go to your android application to continue.

2. Change WRITE_SETTINGS Permission For Android App Example.

  1. You can see this example demo video at the end of this article.
  2. In the above example when you click the button, if this application does not has android.permission.WRITE_SETTINGS permission, then it will pop up the Can modify system settings panel to let the user change the permission to yes.
  3. If the application has the write settings permission, it will pop up an alert dialog and show a message.

3. Change Write Settings Permission Example Source Code.

  1. AndroidManifest.xml
    <manifest xmlns:android=""
        <uses-permission android:name="android.permission.WRITE_SETTINGS" />
            <activity android:name=".permission.WriteSettingsPermissionActivity">
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
  2. Main layout XML file: activity_write_settings_permission.xml
            android:text="Change Write Settings Permission"/>
  3. Main activity java file:
    package com.dev2qa.example.permission;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.provider.Settings;
    import android.view.View;
    import android.widget.Button;
    import com.dev2qa.example.R;
    public class WriteSettingsPermissionActivity extends AppCompatActivity {
        protected void onCreate(Bundle savedInstanceState) {
            setTitle(" - Add Write Settings Permission Example");
            // Get the button and add onClickListener.
            final Button writeSettingsPermissionButton = (Button)findViewById(;
            writeSettingsPermissionButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                    Context context = getApplicationContext();
                    // Check whether has the write settings permission or not.
                    boolean settingsCanWrite = Settings.System.canWrite(context);
                    if(!settingsCanWrite) {
                        // If do not have write settings permission then open the Can modify system settings panel.
                        Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                    }else {
                        // If has permission then show an alert dialog with message.
                        AlertDialog alertDialog = new AlertDialog.Builder(WriteSettingsPermissionActivity.this).create();
                        alertDialog.setMessage("You have system write settings permission now.");
  4. You can see this example demo video on URL

3 thoughts on “How To Grant Write Settings Permission In Android”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.