I am trying to get two Android devices (M & O) to Bluetooth pair via NFC and have only just now managed to get it to partially work after weeks of Googling, trial-and-error and more Googling. At the moment, I have got the devices to successfully pair when the following NDEF message is sent:
// Kotlin code where the 0x7F's are replaced with the sender's BT MAC in little-endian order
val msg = NdefMessage(NdefRecord.createMime("application/vnd.bluetooth.ep.oob", byteArrayOf(0x08, 0x00, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F)));
This is only working because I've hardcoded the BT MAC address in the NDEF record. On the M device I can get the MAC programmatically, but that is no good for O devices. Also, this method requires user permission and I thought that previous working examples entirely bypassed the user
Anyway, my questions are:
If I can't get Android to send the MAC then this whole exercise is pointless since I won't be able to get the MAC addresses of O devices in the wild anyway. Also, if I can't get it to pair without asking the user for permission then what is the point? The pairing process is automatically started just by opening a socket to a known BT MAC address and that (assuming I even know it) can be sent by any arbitrary/proprietary NFC message
Any help with this would be greatly appreciated because the Android NFC docs are absolutely useless on this point and every online example I've managed to find is ancient or assumes that BluetoothAdapter.getAddress() still returns a valid address
Android 9+ doesn't allow getting the local Bluetooth adapter MAC address (stupidly so, really, makes absolutely no sense, the security/privacy gain here is minimal to none and the UX is badly hurt), therefore, you can't do the classic NFC to BT handover (SSP), without hardcoding the MAC address, which means you can't do it.
This is a terrible move by Google which made them also drop "Android Beam" (as it does the same, NFC > BT handover via NDEF SSP).
Google now came up with "NearBy Share" app to replace "Anrdoid Beam", BUT as it relies on the extremely slow Android "NearBy" API, it is also extremely slow (10 seconds to discover and connect!).
Comparing to Apple AirDrop which takes only 3-4 seconds, it is a disaster and Google will probably find that out someday and revert this populistic decision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With