I want to detect if my device is in Airplane mode in order to cancel active network operations. How can I do that?
Asked
Active
Viewed 2,177 times
1 Answers
0
You can use this method:
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isAirplaneModeOn(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} else {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
}
}

Rosário Pereira Fernandes
- 11,015
- 6
- 55
- 79