androidbluetooth-lowenergy

Android BLE connect to device by Name


I'm developing an app that has to connect to a hardware device via bluetooth low energy. The code I'm working with right now enables me to connect just fine, but through the device's address through mBluetoothLeService.connect(String deviceAddress) (where deviceAddress = "F8:AF:BE:04:19:03").

I am looking for a way to allow me to connect to that device by its name and not by its address. If you look at the sample project provided by Google, they use that method to connect to the device, but in the screen where they are scanning for new devices the name of the device does appear. So this field is visible to me, but there is no direct method that I can see which can allow me to do this.

Any help would be appreciated, thanks!


Solution

  • I think there can't be such a method because the name of the device is likely to be ambigious. E.g. all BLE beacons from estimote are called 'Estimote' and so this name is not unique but the mac adresss is.

    If you are sure that all device names are unique, you could use a map to store device names and macs.