val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
if (wifiManager.isWifiEnabled) {
val wifiInfo = wifiManager.connectionInfo
val frequency = wifiInfo.frequency
val is5GHz = frequency in 5_150..5_350 || frequency in 5_470..5_725 || frequency in 5_725..5_825
val is2_4GHz = frequency in 2_400..2_483
if (is5GHz) {
// The network supports 5GHz band
} else if (is2_4GHz) {
// The network supports 2.4GHz band
} else {
// The network supports both 2.4GHz and 5GHz bands
}
} else {
// Wi-Fi is not enabled
}
1条答案
按热度按时间kwvwclae1#
在使用Kotlin的Android中,您可以使用WifiManager类,它提供有关当前Wi-Fi连接的信息
我们需要使用wifiManager对象的isWifiEnabled()方法检查设备是否连接到Wi-Fi网络。