Android wifi getting frequency of the connected Wi

2019-02-10 04:55发布

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?

2条回答
\"骚年 ilove
2楼-- · 2019-02-10 05:05

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" />
查看更多
Lonely孤独者°
3楼-- · 2019-02-10 05:15

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.
查看更多
登录 后发表回答