我的应用与BLE设备配合使用,并通过以下方式(API 21+)搜索它们:
adapter.getBluetoothLeScanner().startScan(filters, scanSettings, this);
这个功能在大多数设备上(例如三星)表现得非常完美,但在一些安装了Android 6.0的LGE和HTC设备上返回null
并崩溃:
由java.lang.NullPointerException引起:尝试调用空对象引用上的'void android.bluetooth.le.BluetoothLeScanner.startScan(java.util.List, android.bluetooth.le.ScanSettings, android.bluetooth.le.ScanCallback)'方法。
该应用程序针对pre-marshmallow Android,因此权限已经被授予(应该已经被授予)。
// 打开蓝牙 if (!adapter.isEnabled()) { logger.debug("启用BLE适配器"); adapter.enable(); }
- 4ntoine