Android wifi getting frequency of the connected Wifi

こ雲淡風輕ζ 提交于 2019-11-30 14:12:54

问题


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?


回答1:


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.



回答2:


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" />


来源:https://stackoverflow.com/questions/13024449/android-wifi-getting-frequency-of-the-connected-wifi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!