Re: [web-bluetooth] How to retrieve a device's name.

Well it's impossible to make it perfect as long as the name is a 
property (unreliable cache) of the device rather than an asynchronous 
operation (delivering the correct name as the result of a promise).

Let me give you some info about my own experiences:

If we talk about Android, I usually myself never use 
BluetoothDevice.getName() since I found out it sometimes returns null 
and I don't really know where it got the name from nor if it is the 
full name. I rather just get the name by parsing the advertisement 
data when I'm handling an advertising device, and explicitly read the 
GATT name characteristic when I'd like to know the name when I'm 
connected. If there is no name in the advertisement data, or only a 
partial name, this is the only reliable way to get the full name.

Since it takes some time to read the name, the property and name cache
 can not be populated directly after the device has been connected. As
 there is no callback when the name has been populated (and I don't 
even know when or if Android requests it), I can't know when to fetch 
it. Therefore I always do my own GATT read. Note that since the name 
reading "occupies" one round trip and I rather want to do other stuff 
before reading the name, I don't read the name immediately after I'm 
connected.

I also don't understand how BluetoothDevice.getName() could be slow. 
It's just a Binder call to the Bluetooth service asking for a cached 
name (see 
https://android.googlesource.com/platform/packages/apps/Bluetooth/+/32a92489e9779d10c613a57d86135a7de6d3d7c4/src/com/android/bluetooth/btservice/AdapterService.java#1132).

Everything also of course depends on how much the developer actually 
cares about the name, if it's just used for display in some UI or if 
it is used in some other way. That said, I think it's perfectly fine 
if the `name` property of the device is the cached advertised name. If
 the user explicitly reads the name GATT characteristic it could be 
updated with that value (or if the underlying stack reads it 
autonomously).

-- 
GitHub Notification of comment by Emill
Please view or discuss this issue at 
https://github.com/WebBluetoothCG/web-bluetooth/issues/299#issuecomment-250014253
 using your GitHub account

Received on Tuesday, 27 September 2016 22:10:43 UTC