我有一个与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.
更多推荐
发布评论