0

I'm trying to get the MAC address of Android devices via Settings.Secure, using the following code:

String btMac = android.provider.Settings.Secure.getString(getApplicationContext().getContentResolver(), "bluetooth_address");

It works for several devices that I've tried, including Samsung Galaxy S6/S7/Pixel/Nexus5. However, on some older phones such as a HTC One X (4.2.2), and another generic Android phone (4.1), the string is null.

Is this a Android version issues? Or is it a vendor build issue, i.e. "bluetooth_address" doesn't exist in Settings.Secure for those builds. Is there anyway to see what's available in Settings.Secure for those devices?

Thanks.

Edit: Could it be because BluetoothManager was only introduced in 4.3, and "bluetooth_name" exists in BluetoothManagerService.java, which doesn't exist prior to 4.3?

user1118764
  • 9,255
  • 18
  • 61
  • 113
  • Even if you figure out why this happens, you will find out that Android 6.0+ does not allow any app to read ANY hardware address. Not sure what you need this for but you should read more here: https://developer.android.com/training/articles/user-data-ids.html#version_specific_details_identifiers_in_m – ᴛʜᴇᴘᴀᴛᴇʟ Feb 22 '17 at 02:59
  • This actually works for Android 6.0+ (tested on the S7/Pixel/Nexus 5). It's not working for the older devices on 4.1/4.2. I think it's because BluetoothManager was only introduced in 4.3. – user1118764 Feb 22 '17 at 03:12

1 Answers1

0

So since BluetoothManager was only introduced in 4.3, this is not possible prior to Android 4.3

user1118764
  • 9,255
  • 18
  • 61
  • 113