简体   繁体   English

BLE设备名称不可检索

[英]BLE Device Name irretrievable

I have a project that is scanning for beacons that run on BLE. 我有一个项目正在扫描在BLE上运行的信标。

I can scan for the beacon and list them in a nice custom ListView just fine. 我可以扫描信标,并在一个不错的自定义ListView列出它们,就好了。 However retrieving their names seems to not work. 但是,检索它们的名称似乎不起作用。

In my OnLeScan callback I use device.getName() which appears to always be returning null? 在我的OnLeScan回调中,我使用device.getName()似乎总是返回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. 此外,当我尝试根据这篇文章解析ScanRecord byte []数组以获取数据时,我还是不太走运。 Any ideas/tips? 有什么想法/提示吗?

Should I be retrieving the local name from the BluetoothDevice class? 我应该从BluetoothDevice类中检索本地名称吗? Should I retrieve it from parsing the ScanRecord/ScanResult class? 我应该从解析ScanRecord/ScanResult类中检索它吗?

Here is what my onLeScan looks like: 这是我的onLeScan的样子:

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. 添加一个案例0x08:如注释中所建议。 However my ListView still lists all found devices as "unknown device" by default and will not retrieve the friendly name. 但是,默认情况下,我的ListView仍将所有找到的设备都列为“未知设备”,并且不会检索友好名称。

See this answer for a breakdown of an iBeacon advertisement packet. 请参阅此答案以了解iBeacon广告包的细分。 There is no name. 没有名字

The official spec is only available via Apple's MFi program. 官方规格仅可通过Apple的MFi程序获得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM