Please note that every device that needs to be connected has a MAC address associated with it, be it a phone or the router. The MAC address for the device can be seen in the WiFi settings in case of the phone. For getting the MAC address of the router, we can use the following code:
WifiManager wifiMgr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
String macAddress = wifiMgr.getConnectionInfo().getBSSID();
Where the basic service set identifier (BSSID) of the current access point is in the form of a six-byte MAC address: XX:XX:XX:XX:XX:XX
The BSSID may be null if there is no network currently connected.
Also, make sure to add the permissions in project's manifest file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
0 Comment(s)