In Android, how does one determine whether the system is in flight mode:
Copy codeThe Code is as follows: public static boolean IsAirModeOn (Context context ){
Return (Settings. System. getInt (context. getContentResolver (),
Settings. System. AIRPLANE_MODE_ON, 0) = 1? True: false );
}
How to switch flight modesCopy codeThe Code is 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
RegisterCopy codeThe Code is 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); cancel
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 the hardware (cell, Bluetooth, wifi) for switching flight modes)Copy codeThe Code is as follows: Settings. System. putString (context. getContentResolver (),
Settings. System. AIRPLANE_MODE_RADIOS, air_mode_radios); air_mode_radios is a string like this. See android/provider/Settings. java in the android source code.
/***
* 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 be disabled when airplane mode
* Is on. This overrides WIFI_ON and then th_on, if Wi-Fi and bluetooth are
* Encoded ded in the comma separated list.
*/
Public static final String AIRPLANE_MODE_RADIOS = "airplane_mode_radios ";
/***
* A comma separated list of radios that shoshould be 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
* Will be turned off when entering airplane mode, but the user will 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 means that the cell, bluetooth, and Wi-Fi hardware in the switching flight mode is switched to the string. We can set the value of this string, to control whether the three hardware is switching the flight mode.