1

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.

Community
  • 1
  • 1
Timothy Frisch
  • 2,995
  • 2
  • 30
  • 64
  • On that parser in the other post I can say that it should have a case 0x08 that is the same as the 0x09 to cover the short name case. 0x09 is the complete name. Aside from that, are you sure the device is actually advertising a name? – Douglas Jones Jun 04 '15 at 14:07
  • Would you say that attempting to retrieve the friendly name from the `BluetoothDevice` from the `onLeScan` is futile in this approach? I've read a lot that the `BluetoothDevice` class can be rather finicky. – Timothy Frisch Jun 04 '15 at 14:09
  • 1
    I generally seeBluetoothDevice.getName() working for me unless the device isn't sending out a name. If you have multiple devices of the same type they almost certainly have the same name so it generally isn't good for showing a list to a user. – Douglas Jones Jun 04 '15 at 14:13
  • I understand. The situation however is that I am actively modifying the friendly name via modification of the firmware from the device manufacturer's API/Application. So I can guarantee that the names are unique. – Timothy Frisch Jun 04 '15 at 14:14

1 Answers1

1

See this answer for a breakdown of an iBeacon advertisement packet. There is no name.

The official spec is only available via Apple's MFi program.

Community
  • 1
  • 1
shebang
  • 1,655
  • 1
  • 12
  • 12
  • When you say "there is no name". I am using a Bleu Station 200 series iBeacon. Would they have modified the iBeacon profile themselves, since on the iOS side of things I see a name? – Timothy Frisch Jun 05 '15 at 16:00
  • 1
    I am familiar with that model. They have an admin mode which advertises as a standard BLE peripheral, including a name. I expect that's where you're seeing the name come from, not from the iBeacon advertisement. – shebang Jun 05 '15 at 16:09
  • That's just it. I downloaded a BLE scanner outside of theirs. Which still advertises the name after admin mode has been left and beacon mode entered. – Timothy Frisch Jun 05 '15 at 16:12
  • Nevermind, you are correct. It does not show up in Beacon mode. – Timothy Frisch Jun 05 '15 at 16:28