How to determine whether the system is currently in flight mode in Android:
Copy Code code as follows:
public static Boolean Isairmodeon (context context) {
Return (Context.getcontentresolver (), Settings.System.getInt (),
Settings.System.AIRPLANE_MODE_ON, 0 = = 1? True:false);
}
How to switch flight mode
Copy Code code as follows:
public static void Setairplanemode (context context, Boolean enabling) {
Settings.System.putInt (Context.getcontentresolver (),
Settings.System.AIRPLANE_MODE_ON, enabling? 1:0);
Intent Intent = new Intent (intent.action_airplane_mode_changed);
Intent.putextra ("state", enabling);
Context.sendbroadcast (Intent);
}
How to register and cancel automatic flight time
Registered
Copy Code code as follows:
Alarmmanager am = (alarmmanager) context
. Getsystemservice (Context.alarm_service);
Intent Intent = new Intent (air_alert_action);
Parcel out = Parcel.obtain ();
Air.writetoparcel (out, 0);
Out.setdataposition (0);
Intent.putextra (Air_raw_data, Out.marshall ());
Pendingintent Sender = pendingintent.getbroadcast (context, 0, intent,
Pendingintent.flag_cancel_current);
Am.set (alarmmanager.rtc_wakeup, Attimeinmillis, sender);
Alarmmanager am = (alarmmanager) context
. Getsystemservice (Context.alarm_service);
Endingintent Sender = pendingintent.getbroadcast (context, 0,
New Intent (action), pendingintent.flag_cancel_current);
Am.cancel (sender);
How to control switching flight mode hardware (CELL,BLUETOOTH,WIFI)
Copy Code code as follows:
Settings.System.putString (Context.getcontentresolver (),
Settings.System.AIRPLANE_MODE_RADIOS, Air_mode_radios); Air_mode_radios for a string like this, look at the Android source android/provider/ Settings.java
/***
* Whether airplane Mode is on.
*/
public static final String airplane_mode_on = "airplane_mode_on";
/***
* Constant for use in Airplane_mode_radios to specify Bluetooth radio.
*/
public static final String Radio_bluetooth = "BLUETOOTH";
/***
* Constant for use in Airplane_mode_radios to specify Wi-Fi radio.
*/
public static final String Radio_wifi = "WIFI";
/***
* Constant for use in Airplane_mode_radios to specify cellular radio.
*/
public static final String Radio_cell = "CELL";
/***
* A Comma separated list of radios that need to is disabled when airplane mode
* is on. This overrides wifi_on and bluetooth_on, if Wi-Fi and BLUETOOTH are
* Included in the Comma separated list.
*/
public static final String Airplane_mode_radios = "Airplane_mode_radios";
/***
* A Comma separated list of radios that should to is disabled when airplane mode
* is on, but can be manually reenabled by the user. For example, if Radio_wifi is
* Added to both Airplane_mode_radios and Airplane_mode_toggleable_radios, then Wifi
* 'll be turned from entering airplane mode, but the user would be able to reenable
* Wifi in the Settings app.
*
* {@hide}
*/
public static final String Airplane_mode_toggleable_radios = "Airplane_mode_toggleable_radios";
If air_mode_radios= "Cell,bluetooth,wifi", this is the switch flight mode is the switch in the string of this cell,bluetooth,wifi hardware, we can set the value of the string, To control whether the three hardware is switched in flight mode is switched state.