Get Bluetooth local mac address in Marshmallow

Eric picture Eric · Oct 27, 2015 · Viewed 37.5k times · Source

Pre Marshmallow my app would obtain it's device MAC address via BluetoothAdapter.getDefaultAdapter().getAddress().

Now with Marshmallow Android is returning 02:00:00:00:00:00.

I saw some link(sorry not sure where now) that said you need to add the additional permission

<uses-permission android:name="android.permission.LOCAL_MAC_ADDRESS"/> 

to be able to get it. However it isn't working for me.

Is there some additional permission needed to get the mac address?

I am not sure it is pertinent here but the manifest also includes

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

So is there a way to get the local bluetooth mac address?

Answer

blobbie picture blobbie · Dec 1, 2015

zmarties is right but you can still get the mac address via reflection or Settings.Secure:

  String macAddress = android.provider.Settings.Secure.getString(context.getContentResolver(), "bluetooth_address");