如何扫描wifi或检查wifi是否为2.4 ghz频段



在我的应用程序(MIN SDK 19(中,我需要列出2.4ghz频段的所有wifi,并区分5ghz频段的wifi。

我发现了这篇文章,但它似乎与我所需要的并不精确,因为它似乎是为android API中的开发人员删除或隐藏的代码:仅在2.4Ghz波段中扫描wifi信号

在这里,您可以找到频率列表:安卓wifi获取连接的wifi 的频率

即使在这里:https://en.wikipedia.org/wiki/List_of_WLAN_channels#2.4_GHz_(802.11b/g/n/ax(

我不理解所有这些频率,因为使用WifiManager,它会返回我,对于5GHz,频率值低于2500。

我需要知道如何获得无线网络2.4ghz频带。

2.4 GHz网络的频率范围为2400至2500 MHz。

扫描WiFi网络后,您会得到一个类型列表"ScanResult",因此,您可以迭代此列表并检查每个元素。

// Get WiFi Scan results
val wifiManager = this.getSystemService(Context.WIFI_SERVICE) as WifiManager
val results = wifiManager.scanResults
// Create a new list to store the filtered WiFis
val wifi24Only = ArrayList<ScanResult>()
// Check each 'frequency' property and add to the list if it is in 2.4 GHz range
for (wifi in results) {
if (wifi.frequency in 2400..2500) {
wifi24Only.add(wifi)
}
}
// The list has only the scanned WiFis which are in the 2.4GHz range
print(wifi24Only)

Obs.:您必须创建一个新列表(如"wifi24Only"(,因为您不应该更改"results"上的值,因为wifiManager仍在使用它。

最新更新