本文介绍了如何让所有的WiFi接入点的BSSID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我需要得到所有AP的BSSID(MAC)。请从下面code座。

I need to get BSSID(MAC) of all AP's. Please find below code block.

    List<WifiConfiguration> test =  wifiManager.getConfiguredNetworks();
    for(int k=0;k<test.size();k++){
        Log.d("acheck", "test BSSID = "+test.get(k).BSSID);
        Log.d("acheck", "test BSSID = "+test.get(k).BSSID);
   }

但上面的code块返回SSID正常,但空的BSSID。我想与用户定义的SSID连接到最强的接入点。是否有任何API方法可用来获得最佳信号强度的AP根据用户定义的SSID。(在我的情况下,有很多的SSID的与多个AP的可用单一SSID)

But above code block returns SSID properly but null for BSSID. I want to connect to strongest access point with user defined SSID. Is there any API method available to get best signal strength's AP with user defined SSID.(In my case there are many SSID's with single SSID with multiple AP's available.)

推荐答案

改编@ToonSuperLove答案,主要是为了避免NPE的。

Adapted the answer by @ToonSuperLove, mainly to avoid NPEs.

public class WifiTest extends Activity {

    public void loadWifiAvailableList(EditText etWifiList) {
        WifiManager wifiManager = (WifiManager)
                                    getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> results = wifiManager.getScanResults();
        String message = "No results. Check wireless is on";
        if (results != null) {
            final int size = results.size();
            if (size == 0) message = "No access points in range";
            else {
                ScanResult bestSignal = results.get(0);
                etWifiList.setText(""); // etWifiList is EditText
                int count = 1;
                for (ScanResult result : results) {
                    etWifiList.append(count++ + ". " + result.SSID + " : "
                            + result.level + "\n" + result.BSSID + "\n"
                            + result.capabilities + "\n"
                            + "\n=======================\n");
                    if (WifiManager.compareSignalLevel(bestSignal.level,
                            result.level) < 0) {
                        bestSignal = result;
                    }
                }
                message = String.format(
                        "%s networks found. %s is the strongest.", size,
                        bestSignal.SSID + " : " + bestSignal.level);
            }
        }
        Toast.makeText(this, message, Toast.LENGTH_LONG).show();
    }
}

这篇关于如何让所有的WiFi接入点的BSSID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 16:34