Get the MAC address of bluetooth adapter in Android

Viewed 6072

I'm trying to get the MAC address of bluetooth in my android device. So I'm using the following method:

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
String macAddress = mBluetoothAdapter.getAddress();

The address returned is 02:00:00:00:00:00. I've seen questions and posts saying that it's not possible anymore to get your MAC address in android unless your application is a System Application.

So what if I really need to get the MAC address of my phone?? It's impossible to do it or what?

Note: I know this question is asked lots of times on SO, but most of the answers are out of date.

2 Answers

For security reasons this functionality is not available on Android since Android version 6.0 [source]:-

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.

The reason for this is to stop random applications gaining information about the phone's hardware addresses therefore violating the privacy/data protection.

I hope this helps.

What Youssif Saeed said in the other answer was correct. Android won't let us get the MAC address anymore.

Brief description about what I want:

Let's say I have a phone with MAC Address X, and I have another nearby device with MAC address B. When the two devices are nearby each other. I was able to get the MAC address of the other device using BluetoothDevice and getAddress() method from ScanResult.getDevice(). So what I still need is to catch my own device MAC address so that in the backend I save each user with his MAC address, and when I catch it in bluetooth, I know who's nearby me

Here's the workaround I've done in order to send some data between near devices.

I found something called Nearby Messages API. It is available for Android and iOS and very easy to implement. Now I'm able to catch near devices with my application installed on them, and send a unique Id generated by the application to identify the user.

Related