agustinaliagac
agustinaliagac

Reputation: 849

BluetoothDevice always returns null on getName()

I'm facing this issue consistently in Android 4.4, 5 and 6.

I'm performing a BLE Bluetooth devices scan and after it I can access their address (getAddress()), and other data. But if I call device.getName() it returns null EVERY TIME.

This documentation is not helpful, it only says that returns null if "there was a problem" : https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getName()

Other posts that I visited unsuccessfully :

https://code.google.com/p/android/issues/detail?id=34411

android BluetoothDevice.getName() return null

ble device bluetoothdevice.getname() returns null

PS: I'm using non-deprecated methods in Android API level 21+, so that's not related to the issue.

Any idea about what could be going wrong here?

Upvotes: 1

Views: 4625

Answers (2)

Emil
Emil

Reputation: 18452

I'm not using getName() anymore since it seems undefined when it returns a real name (and if so how old is this cached name?) and when it is null. Just parse the scanRecord in the advertisement data and get the name from there OR read the name characteristic in the GATT DB if you are connected.

Upvotes: 1

CaseyB
CaseyB

Reputation: 25058

It could be that your BLE device isn't broadcasting a name. The broadcast payload is limited to 31 bytes and some manufacturers omit a name to save room.

Upvotes: 1

Related Questions