Upto API level 16, it is possible to turn on/off airplane mode in Android devices. From API level of 17, it seems like the Settings.Global
, which is read only has replaced the Settings.System
.
I want to know that, is it possible to turn on/off the airplane mode programmatically in android wear (Moto 360) which isn't rooted.
This code works properly on Rooted Device.
To Turn ON:
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Process process;
process = Runtime.getRuntime().exec("su -c settings put global airplane_mode_on 1;am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
To Turn Off:
b2=(Button)findViewById(R.id.button1);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Process process;
process = Runtime.getRuntime().exec("su -c settings put global airplane_mode_on 0;am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});