Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android wifi getting frequency of the connected Wifi

Well i have ScanResults and from there i can have SSID , BSSID , Frequency of all the wifi's.

List<ScanResult> results = wifi.getScanResults();

Also i have the Connected wifi info so from there also i am having SSID of connected and BSSID of the connected wifi.

WifiManager wifi;
WifiInfo info;
wifi = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
info = wifi.getConnectionInfo();

Now i only want to have the frequency of the connected wifi but when i check SSID and BSSID they can be same for 2 network. Now how can i find the frequency of the connected Wifi.

Also from that wifi i want to have corresponding channel no.

i found a table for that

CHANNEL NUMBER LOWER Freq(GHZ) CENTER Freq(GHZ) UPPER Freq(GHZ)

1 2401 2412 2423

2 2404 2417 2428

3 2411 2422 2433

4 2416 2427 2438

5 2421 2432 2443

6 2426 2437 2448

7 2431 2442 2453

8 2436 2447 2458

9 2441 2452 2463

10 2451 2457 2468

11 2451 2462 2473

12 2456 2467 2478

13 2461 2472 2483

14 2473 2484 2495

Want to know whether sdk always provides center freq of this table and also what abt other freq like 5Ghz etc?

like image 409
Amit Hooda Avatar asked Oct 23 '12 06:10

Amit Hooda


People also ask

How do I change from 2.4 GHz to 5GHz on Android 12?

If you go to the hotspot settings menu on an Android 11 device, you'll see an option to choose an access point (AP) band between the older 2.4GHz band or a dual mode labelled "5.0GHz band preferred." In Android 12 DP3, this choice is hidden under the "Advanced" drop-down menu, and it's re-labelled.


2 Answers

The frequency from WifiInfo is only available since Lollipop (API 21) http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getFrequency()

android.net.wifi.WifiInfo

public int getFrequency ()

Returns the current frequency in FREQUENCY_UNITS.
like image 172
xiaomi Avatar answered Oct 20 '22 16:10

xiaomi


You Can Try.

 WifiManager wifiMgr = (WifiManager) getContext().getSystemService(context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
     int frequency = wifiInfo.getFrequency();

Add Following Permission.

 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
like image 38
Quantum4U Avatar answered Oct 20 '22 17:10

Quantum4U