我正在尝试构建一个使用BLE的应用。我在运行Android 5.0.1的三星Galaxy S5上测试这个应用程序。当我尝试扫描蓝牙设备时,我立即在日志中找到它:
03-25 17:39:41.235 2696-2714/com.example.multiplayertest D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=7
03-25 17:39:41.245 2696-2696/com.example.multiplayertest I/System.out: -99
03-25 17:39:41.245 2696-2696/com.example.multiplayertest I/System.out: failed
扫描失败,错误代码为-99。我无法找到这意味着什么,你可以给予任何帮助。
扫描码:
final BluetoothLeScanner scanner = bluetoothAdapter.getBluetoothLeScanner();
final ArrayList<ScanFilter> filterList = new ArrayList<>();
ScanFilter.Builder scanBuilder = new ScanFilter.Builder();
scanBuilder.setServiceUuid(new ParcelUuid(serviceUuid));
filterList.add(scanBuilder.build());
ScanSettings.Builder settingsBuilder = new ScanSettings.Builder();
settingsBuilder.setScanMode(ScanSettings.SCAN_MODE_BALANCED);
scanner.startScan(filterList, settingsBuilder.build(), scanCallback);
和scanCallback:
ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
System.out.println("Result");
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
System.out.println("Results");
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
System.out.println(errorCode);
System.out.println("failed");
}
};