扫描Ble Android / getName()或设备未完成或为空(Scan Ble Android / getName() or device not complete or null)

编程入门 行业动态 更新时间:2024-10-25 05:13:48
扫描Ble Android / getName()或设备未完成或为空(Scan Ble Android / getName() or device not complete or null)

我有一个与Android的BLE扫描有关的问题,我没有得到所发现的扫描设备的全名,我只得到第一个字母,你有什么想法如何解决这个问题?

我正在使用支持BLE的7.0牛轧糖设备

这是我的代码的一部分:

mBluetoothScanner = mBluetoothAdapter.getBluetoothLeScanner(); settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER) .build(); if (Build.VERSION.SDK_INT >= 21) { mScanCallback = new ScanCallback() { @Override public void onScanResult(int callbackType, ScanResult result) { messageLog.error("onScanResult"); BluetoothDevice btDevice = null; if (Build.VERSION.SDK_INT >= 21) { btDevice = result.getDevice(); messageLog.error("btDevice : " + btDevice.getName() + "|" + btDevice.getAddress() + "|" + Arrays.toString(btDevice.getUuids())); } if (btDevice != null && btDevice.getName() != null && !isInDeviceList(btDevice)) mDeviceList.add(btDevice); } @Override public void onBatchScanResults(List<ScanResult> results) { } @Override public void onScanFailed(int errorCode) { Log.e("Scan Failed", "Error Code: " + errorCode); } }; }

使用btDevice.getName()我只能得到扫描设备的第一个字母,这是我的错,还是来自Android BLE API?

I'have an issue with the BLE scan of Android, I dont get the full name of the scanned devices found, I get only the first letter do you have any idea how to resolve this issue ?

I'm working with a 7.0 Nougat device which is supporting BLE

This is a part of my code :

mBluetoothScanner = mBluetoothAdapter.getBluetoothLeScanner(); settings = new ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER) .build(); if (Build.VERSION.SDK_INT >= 21) { mScanCallback = new ScanCallback() { @Override public void onScanResult(int callbackType, ScanResult result) { messageLog.error("onScanResult"); BluetoothDevice btDevice = null; if (Build.VERSION.SDK_INT >= 21) { btDevice = result.getDevice(); messageLog.error("btDevice : " + btDevice.getName() + "|" + btDevice.getAddress() + "|" + Arrays.toString(btDevice.getUuids())); } if (btDevice != null && btDevice.getName() != null && !isInDeviceList(btDevice)) mDeviceList.add(btDevice); } @Override public void onBatchScanResults(List<ScanResult> results) { } @Override public void onScanFailed(int errorCode) { Log.e("Scan Failed", "Error Code: " + errorCode); } }; }

With btDevice.getName( ) I only get the first letter of a device scanned, is this my fault or is it coming from the Android BLE API ?

最满意答案

如果外围设备的名称不适合广告数据,因为它需要在其中包含其他数据,它只会通过无线发送名称的前缀。 除了更改外设固件中的广告数据之外,您无能为力。

要获取确切的广告数据,您可以调查onScanResult中的“result.getScanRecord()”ScanRecord。

If the peripheral's name does not fit in the Advertising data since it needs to include other data therein, it will only send the prefix of the name over the air. It's nothing you can do about that other than change the advertisement data in the peripheral's firmware.

To get the exact advertisement data, you can investigate the "result.getScanRecord()" ScanRecord in onScanResult.

更多推荐

本文发布于:2023-07-22 10:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:未完成   为空   设备   getName   Ble

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!