I need to obtain the MAC address of my android device using Java. I've searched online, but I haven't found anything useful.
How to find the device MAC address of your Android mobile device Open settings of your device. Scroll down and select “About phone“. For Android 11 and higher you can here find the randomised MAC addresses for each SSID already used as well as the permanent MAC address of your phone.
I think without a rooted device it's not possible to spoof a MAC address on Android because on "end-user mode", you don't have enough privilege. If you need, to change your MAC Address of your device, you should perhaps consider to root your it.
As was already pointed out in the comment, the MAC address can be received via the WifiManager.
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); String address = info.getMacAddress();
Also do not forget to add the appropriate permissions into your AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Please refer to Android 6.0 Changes.
To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.
To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions.
Getting the MAC address through WifiInfo.getMacAddress()
won't work on Marshmallow and above, it has been disabled and will return the constant value of 02:00:00:00:00:00
.
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