title: java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS
body: <p>This is my code by which i am building airplan mode On/OFF on Platform 5.0.0
  below is mine Activity.java source code please  suggest the changes which i need to do in manifeast.xml for access the permission.</p>
  
  <pre><code>package com.rjil.airplanemodeonoff;
  
  import android.content.Intent;
  import android.os.Build;
  import android.provider.Settings;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.TextView;
  import android.widget.ToggleButton;
  
  public class MainActivity extends AppCompatActivity {
      // constants
      static final String STATUS_ON = "Airplane Mode: ON";
      static final String STATUS_OFF = "Airplane Mode: OFF";
  
      static final String TURN_ON = "Turn ON";
      static final String TURN_OFF = "Turn OFF";
  
      // controls
      TextView TVAirplaneMode;
      ToggleButton tBAirplane;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          // load controls
          TVAirplaneMode = (TextView)findViewById(R.id.TVAirplaneMode);
          tBAirplane = (ToggleButton)findViewById(R.id.tBAirplane);
          // update UI at first time loading
          updateUI(isAirplaneMode());
          // set click event for button
          tBAirplane.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // check current state first
                  boolean state = isAirplaneMode();
                  // toggle the state
                  if (state) toggleAirplaneMode(0, state);
                  else toggleAirplaneMode(1, state);
                  // update UI to new state
                  updateUI(!state);
              }
          });
      }
      public void toggleAirplaneMode(int value, boolean state) {
          // toggle airplane mode
          //check the version
          if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.LOLLIPOP) { //if less than verson 4.2
              Settings.System.putInt(
                      getContentResolver(),
                      Settings.System.AIRPLANE_MODE_ON, value);
          } else {
              Settings.Global.putInt(
                      getContentResolver(),
                      Settings.Global.AIRPLANE_MODE_ON, value);
          }
          // broadcast an intent to inform
          Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
          intent.putExtra("state", !state);
          sendBroadcast(intent);
      }
  
      public void updateUI(boolean state) {
          //set text according to state
          if(state) {
              TVAirplaneMode.setText(STATUS_ON);
              tBAirplane.setText(TURN_OFF);
          } else {
              TVAirplaneMode.setText(STATUS_OFF);
              tBAirplane.setText(TURN_ON);
          }
      }
  
  
      public boolean isAirplaneMode() {
          //check the version
          if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.LOLLIPOP) {//if less than verson 4.2
              return Settings.System.getInt(getContentResolver(),
                      Settings.System.AIRPLANE_MODE_ON, 0) != 0;
          } else {
              return Settings.Global.getInt(getContentResolver(),
                      Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
  
          }
      }
  
  
  
  }
  </code></pre>