Reputation: 3313
I need to disable airplane mode in my kiosk app, i tried snippet below to overwrite device settings
try {
int airplane = Settings.System.getInt(getApplicationContext().getContentResolver(), "airplane_mode_on");
if (airplane == 1) {
getApplicationContext().sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE").putExtra("state", false));
}
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
This code seems to work up to android version 4.0, whereas in 4.1 and above it doesn't works.I hope to make it work by rooting the device to access the system settings. Actually my task to disable airplane mode feature from status bar in nexus tablet. Let me know any suggestions on these to implement.
Upvotes: 4
Views: 1791
Reputation: 4226
For Android <= 4.1:
static boolean getAirplaneMode(Context context)
{
return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
static void setAirplaneMode(Context context, boolean mode)
{
if (mode != getAirplaneMode(context))
{
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, mode ? 1 : 0);
Intent newIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
newIntent.putExtra("state", mode);
context.sendBroadcast(newIntent);
}
}
For Android 4.2 have a look at Modify AIRPLANE_MODE_ON on Android 4.2 (and above)
Upvotes: 2