Get Bluetooth Local MAC Address in Marshmallow

Get Bluetooth local mac address in Marshmallow

As it turns out, I ended up not getting the MAC address from Android. The bluetooth device ended up providing the Android device MAC address, which was stored and then used when needed. Yeah it seems a little funky but on the project I was on, the bluetooth device software was also being developed and this turned out to be the best way to deal with the situation.

Android get bluetooth address in marshmallow

Access to the mac address has been deliberately removed:

http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html

use this code :
get the mac address via reflection or Settings.Secure:

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

How to get bluetooth device mac address by stored device name

I think it's impossible.You can't get the mac address only from a known device name.The bluetooth device name is not the key element for the bluetooth connection and communication,but the mac address will be.Only you can get the mac address according to the device name if you has pre-stored the related BluetoothDevice object and the name is different from the others.

Getting Mac Address on Marshmallow In Xamarin

Try using this code:

public string GetMacAdress(Context context)
{
string mac = GetMacAddressLegacy(context);

if (mac == "02:00:00:00:00:00")
{
var interfaces = Java.Net.NetworkInterface.NetworkInterfaces;

foreach (var nif in interfaces)
{
if (!nif.Name.ToLower().Contains("wlan")) continue;

byte[] macBytes = nif.GetHardwareAddress();

string macString = BitConverter.ToString(macBytes);
if (!string.IsNullOrWhiteSpace(macString))
mac = macString.Trim().ToUpper().Replace("-", ":");
}
}

return mac;
}


Related Topics



Leave a reply



Submit