Reputation: 400
I have the following code which lists the ssid and rssi of all networks in range:
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());
}
}
However calling wifiInf.getMacAddress();
always returns the same generic address. I've read that this worked until Android 6.0. All solutions I could find list only your own mac address and not of all networks. Is there a way to get the mac address and rssi of all networks in range?
Upvotes: 0
Views: 139
Reputation: 11
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);
}
you can try this bro
Upvotes: 1