萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> 安卓開發 >> android 判斷當前是否是飛行模式

android 判斷當前是否是飛行模式

 在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 ………
}
}
}

copyright © 萬盛學電腦網 all rights reserved