1.判斷是否飛行模式:
private boolean isAirPlaneModeOn(){
int mode = 0;
try {
mode = Settings.Global.getInt(getContentResolver(), Settings.Global.AIRPLANE_MODE_ON);
}catch (SettingNotFoundException e) {
e.printStackTrace();
}
return mode == 1;//爲1的時候是飛行模式
}
2.廣播監聽飛行模式:
private BroadcastReceiver airplaneModeOn = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(Intent.ACTION_AIRPLANE_MODE_CHANGED)){//飛行模式狀態改變
//To Do
}
}
};
註冊廣播:
IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(airplaneModeOn, filter);