Actually in my Project I want to automatically change flight mode and auto rotate settings, and also I tried many links in stakcoverflow, and many other sites too
and Im using that, but nothing happened in execution.
For Flight Mode
public void actFlight(int val)
{
switch(val)
{
case 0:
Log.v("Mani", "Flight 0");
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1);
break;
case 1:
Log.v("Mani", "Flight 1");
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
break;
case 2:
Log.v("Mani", "Flight 2");
boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
// toggle airplane mode
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
break;
}
}
the val is 0, 1 or 2
0 for switch airplane mode on
1 for switch airplane mode off
2 for switch airplane mode toggle
I used to change auto rotation settings as above, it working perfectly, But I can’t toggle airplane mode,
and I also compared many times with some other examples
no error is showing, and no change in settings… what can I do..
Note: I defined and calling this function in the SERVICE (and auto rotation too)
You need to send Broadcast with
Intent.ACTION_AIRPLANE_MODE_CHANGEDchange your code as:NOTE ::-
MAKE SURE YOU HAVE THESE PERMISSIONS IN manifest.xml :