【问题标题】:Scan Ble Android / getName() or device not complete or nullScan Ble Android / getName() 或设备不完整或为空
【发布时间】:2017-04-25 09:39:24
【问题描述】:

我对 Android 的 BLE 扫描有问题,我没有找到找到的扫描设备的全名,我只收到第一个字母你知道如何解决这个问题吗?

我正在使用支持 BLE 的 7.0 Nougat 设备

这是我的代码的一部分:

   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?

【问题讨论】:

    标签: android embedded bluetooth-lowenergy


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,我会尝试更改固件中的名称,我会告诉你它是否工作。我已经尝试过“result.getScanRecord()”并且我已经设法获得了 8 个首字母,你认为它是一个固定的字节数吗?
    • 谢谢先生 :) 我使用了 result.getScanRecord() 而不是 getName 并更改了固件中的名称,祝你有美好的一天!
    猜你喜欢
    • 1970-01-01
    • 2021-05-24
    • 2021-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多