在AirplaneModeEnabler中 提供了isAirplaneModeOn方法來判斷當前是否是Airplane mode:
public static boolean isAirplaneModeOn(Context context) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} www.2cto.com
偵聽是否airplane mode 發生改變,可以用注冊intentFilter 來偵聽。
BroadcastReceiver mReceiver = new AirplaneModeBroadcastReceiver();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(mReceiver, intentFilter);
private class AirplaneModeBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)) {
// add your code here ………
}
}
}