2

In my app (MIN SDK 19) I need to list all wifis that are from the 2.4ghz band and discriminate those from the 5ghz band.

I found this post but it does not seem to be precise with what I need since it seems that the code was removed or hidden for the developers in the android API: Scanning for wifi signals only in 2.4Ghz band

Here you can find a list of frequencies: Android wifi getting frequency of the connected Wifi

Even here: https://en.wikipedia.org/wiki/List_of_WLAN_channels#2.4_GHz_(802.11b/g/n/ax)

I dont understand at all this frequencies because using WifiManager it is returning me, for 5 Ghz, a frequency value below 2500.

I need to know just how to get wifi 2.4ghz band.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Deneb Chorny
  • 391
  • 3
  • 19

1 Answers1

0

The frequencies of 2.4 GHz networks are in the range of 2400 to 2500 MHz.

After scanning for WiFi networks you get a list of types 'ScanResult' as a result, you can iterate this list and check each element.

// 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.: You must create a new list (like the 'wifi24Only') as you should not change values on 'results', because wifiManager is still using it.

kha
  • 256
  • 2
  • 7