1. 程式人生 > >Android對飛航模式下BT、WiFi開關控制

Android對飛航模式下BT、WiFi開關控制

Android對飛航模式下Wifi和藍芽的控制通過如下兩個資料庫中的值控制:

airplane_mode_radiosairplane_mode_toggleable_radios,其值儲存在Setting資料庫Global表中.

/**

 * A comma separated list of radios that need to be 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";

通過註釋,可以看出,該值表示在開啟飛航模式的時候需要關閉的radios,以逗號分隔。

若需要在開啟飛航模式的時候關閉wifi和bluetooth,這該值為”wifi,bluetooth”

 

/**

 * A comma separated list of radios that should to 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";

通過註釋,可以看出,該值表示在飛航模式下還能開啟的radios(使用者可以手動開啟),以逗號分隔。

若需要在飛航模式下仍能夠開啟wifi和bluetooth,這該值為”wifi,bluetooth”

 

Radios列表項:

/**

 * 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";

/**

 * {@hide}

 */ 
public static final String RADIO_WIMAX = "wimax";

/**

 * Constant for use in AIRPLANE_MODE_RADIOS to specify Cellular radio.

 */ 
public static final String RADIO_CELL = "cell";

/**

 * Constant for use in AIRPLANE_MODE_RADIOS to specify NFC radio.

 */ 
public static final String RADIO_NFC = "nfc";

 

預設值配置的位置如下:

/frameworks/base/packages/SettingsProvider/res/values/defaults.xml

<bool name="def_airplane_mode_on">false</bool>

<bool name="def_theater_mode_on">false</bool>

<!-- Comma-separated list of bluetooth, wifi, and cell. -->

<string name="def_airplane_mode_radios" translatable="false">cell,bluetooth,wifi,nfc,wimax</string>

<string name="airplane_mode_toggleable_radios" translatable="false">bluetooth,wifi,nfc</string>