我有以下代码,列出了范围内所有网络的ssid和rssi:

    public static void getWIFI(Context context) {
        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

        WifiInfo wifiInf = wifiManager.getConnectionInfo();
        String macAddr = wifiInf.getMacAddress();

        final List<ScanResult> results = wifiManager.getScanResults();

        if (results != null) {
            StringBuffer buf = new StringBuffer();

            for (int i = 0; i < results.size(); i++) {
                String ssid = results.get(i).SSID;
                float rssi = results.get(i).level;
                buf.append(ssid + ": " + rssi + "\n");
            }

            Log.i("W-LAN", buf.toString());
        }
    }


但是,调用wifiInf.getMacAddress();总是返回相同的通用地址。我已经读到这在Android 6.0之前有效。我能找到的所有解决方案仅列出您自己的mac地址,而不列出所有网络。有没有办法获取范围内所有网络的mac地址和rssi?

最佳答案

 for (ScanResult scanResult : scanResults) {
    Map hashMap = new HashMap();
    hashMap.put("wifiMac", scanResult.BSSID == null ? "" : scanResult.BSSID);
    hashMap.put("ssid", scanResult.SSID);
    hashMap.put("rssi", scanResult.level);
    arrayList.add(hashMap);
}


你可以试试这个兄弟

07-25 23:37