在AirplaneModeEnabler中 提供了isAirplaneModeOn方法来判断当前是否是Airplane mode:
public static boolean isAirplaneModeOn(Context context) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
侦听是否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 ………
}
}
}
时间: 2024-10-28 14:14:45