Search code examples
javaandroidwifimac-address

Get Mac address of listed WIFI's on Android


Is there a way for me to get the mac address of every wifi in wifi list?

My current code is as follows:

        wifiList = mainWifi.getScanResults();

        JSONArray requestData = new JSONArray();

        for (int i = 0; i < wifiList.size(); i++) {
            JSONObject wifiNetwork = new JSONObject();

            try {
                wifiNetwork.put("MSource", "WIFI");
                wifiNetwork.put("MName", (wifiList.get(i)).SSID);

                // this way I am getting mac address of current device.
                wifiNetwork.put("MAddress", mainWifi.getConnectionInfo().getMacAddress());

                wifiNetwork.put("MCreatedOn", "Some date time");
            } catch (JSONException e) {
                e.printStackTrace();
            }   
        }

Solution

  • You should use getBSSID() from getConnectionInfo(), instead of getMacAddress() (which return the mac of current connection).