I wrote the following code to get the MAC address:
WifiManager wimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String address = wimanager.getConnectionInfo().getMacAddress();
Log.d("TOKEN", address);
This works perfectly on my phone, but in the Android emulator it returns null. Is this because the Android emulator doesn't have a MAC address?
It's the same as when you try getting a hold of the bluetooth stuff on the emulator. There is no MacAdress and should return null.
Launch the Terminal Emulator. Just type the following command: ip link set wlan0 address XX:XX:XX:YY:YY:YY, where wlan0 is the name of the interface and XX:XX:XX:YY:YY:YY is the MAC address you want to set.
Android PhoneOn the Home screen, tap the Menu button and go to Settings. Tap About Phone. Tap Status or Hardware Information (depending on your model of phone). Scroll down to see your WiFi MAC address.
To find the device ID of a locally connected Android device or emulator, use the adb devices command.
It's the same as when you try getting a hold of the bluetooth stuff on the emulator. There is no MacAdress and should return null. Try on a real device and it will work. The code is correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With