-1

I am trying to programmatically on/off the airplane mode in android, I rooted my device even install app as a system app but still troubling to achieve. below is my code

 public void toggleAirplaneMode(int value, boolean state) {
        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);
    }

calling the function by for turn off the airplane mode 
   toggleAirplaneMode(0,true);

calling the function by for turn on the airplane mode toggleAirplaneMode(1,false);

it's throw exception permission denial: writing to secure settings requires android.permission.write_secure_settings

I Already rooted the device and installed the app as a system app in my manifest permissions

  <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
 <uses-permission android:name="android.permission.WRITE_SETTINGS" />

Help me to solve this issue.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Paradox
  • 11
  • 1
  • 1
  • This question is already asked here, [Turn ON-OFF airplane mode in any api](https://stackoverflow.com/a/37762773/9528882) – Bikash Sahani Jul 11 '18 at 07:46

1 Answers1

0

did you ask for superuser permission

Process root = Runtime.getRuntime().exec("su");

before running your code?

seyed Jafari
  • 1,235
  • 10
  • 20