Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically getting the MAC of an Android device

I need to obtain the MAC address of my android device using Java. I've searched online, but I haven't found anything useful.

like image 491
TSW1985 Avatar asked Jul 29 '12 01:07

TSW1985


People also ask

How do I find the MAC address on Android 11?

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.

Can you spoof a MAC address on Android?

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.


2 Answers

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.

like image 164
Konrad Reiche Avatar answered Sep 19 '22 19:09

Konrad Reiche


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.

like image 38
minipif Avatar answered Sep 20 '22 19:09

minipif