Reputation: 155
I am using the following code to find all access points near to me.
We start the scanner with
registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifiManager.startScan();
and get the results using a BroadcastReceiver
BroadcastReceiver wifiReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
List<ScanResult> scanResults = wifiManager.getScanResults();
unregisterReceiver(this);
for (ScanResult result : scanResults) {
//some code...
}
}
};
Now, by using ScanResults
we can get features like ssid
, bssid
or capabilities
etc. but I can't find a way to get ssid's frequency band. Is it possible?
Upvotes: 1
Views: 547
Reputation: 5614
In ScanResult
, the frequency
field is how you can determine the band of the AP.
Specifically, the band would be 5GHz if frequency
> 5000, and 2.4GHz if 3000 > frequency
> 2000 (around 2400).
According to the 802.11 standard, it specifies that the 5GHz band's starting frequency is 5000MHz and 2.4GHz band's starting frequency is 2047MHz, the frequency you get from ScanResult#frequency
will differ because of the different channels they are in.
The specific formula that converts the starting (base) frequency to the center (result) frequency is
freqCenter = freqStart + 5 * channelNumber
With that, you can derivate the channel number of the AP.
Upvotes: 4