注意:这些 api 已从 Android Nogut 版本中删除。适用于棉花糖
/**
* Auto settings in the driver. The driver could choose to operate on both
* 2.4 GHz and 5 GHz or make a dynamic decision on selecting the band.
* @hide
*/
public static final int WIFI_FREQUENCY_BAND_AUTO = 0;
/**
* Operation on 5 GHz alone
* @hide
*/
public static final int WIFI_FREQUENCY_BAND_5GHZ = 1;
/**
* Operation on 2.4 GHz alone
* @hide
*/
public static final int WIFI_FREQUENCY_BAND_2GHZ = 2;
使用 WifiManager.java 的上述常量部分来设置所需的频段。我们可以使用 API setFrequencyBand(int mode, boolean persist) 设置频率。这些是隐藏的 API。
代码片段:
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
// To scan only 2.4 GHz Frequency band
// true, if this needs to be remembered
wm.setFrequencyBand(2, false);
// Start scan.
wm.startScan();
// To get the frequency band used.
int band = wm.getFrequncyBand();