Did I make a mistake? It's not working.
public void airplane() { boolean isEnabled = Settings.System.getInt(this.getApplicationContext().getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled ? 0 : 1); //Settings.System.putInt(this.getApplicationContext().getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled ? 0 : 1); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); }
This answer contains code necessary to do this. Also make sure you have the WRITE_SETTINGS
permission.
Adapted from Controlling Airplane Mode:
// read the airplane mode setting boolean isEnabled = Settings.System.getInt( getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; // toggle airplane mode Settings.System.putInt( getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1); // Post an intent to reload Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", !isEnabled); sendBroadcast(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With