1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| public static boolean isAirplaneModeOn(Context context) {
// indique si le mode avion est on ou off
return Settings.System.getInt(context.getContentResolver (),Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
public void setAirplaneMode(Context context) {
// swith du mode avion
boolean isAirplaneModeOn = isAirplaneModeOn(context);
if(isAirplaneModeOn) {
Toast.makeText(getApplicationContext(), "Mode avion désactivé", Toast.LENGTH_SHORT).show();
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", 0);
context.sendBroadcast(intent);
}
else {
Toast.makeText(getApplicationContext(), "Mode avion activé", Toast.LENGTH_SHORT).show();
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", 1);
context.sendBroadcast(intent);
}
} |
Partager