I have a project that is scanning for beacons that run on BLE.
I can scan for the beacon and list them in a nice custom ListView
just fine. However retrieving their names seems to not work.
In my OnLeScan
callback I use device.getName()
which appears to always be returning null?
Furthermore, when I attempt to parse the ScanRecord byte[] array for the data in concordance with this post - I still am not having much luck. Any ideas/tips?
Should I be retrieving the local name from the BluetoothDevice
class? Should I retrieve it from parsing the ScanRecord/ScanResult
class?
Here is what my onLeScan looks like:
public void onLeScan(final BluetoothDevice device, int rssi, final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.v(device.getName(),device.getName());
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
}
}
});
}
Edit:
I attempted some modification of the code from the linked post. Adding a case 0x08: as suggested in the comments. However my ListView still lists all found devices as "unknown device" by default and will not retrieve the friendly name.