I'm not good at English, so I use a translator to leave questions like this.
Currently, we are looking for a solution for Bluetooth scanning.
Too many Bluetooth scans are returning the following error:
D/Bluetooth LeScanner: Register Scanner () - Status=6 ScannerId=-1ms ScannerID=0
I don't see a solution to this problem, so I leave a question like this.
ScanCallback
public ScanCallback scanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
BleDevicesAdd(result);
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
for ( ScanResult result : results){
BleDevicesAdd(result);
}
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
System.out.println("onScanFailed" + errorCode);
}
};
devicesAdd
public void BleDevicesAdd(ScanResult result){
BluetoothDevice device = result.getDevice();
if ( device != null){
String deviceName = device.getName();
if ( deviceName != null){
if ( deviceName.toLowerCase().startsWith("test")){
boolean bIsExist = false;
for (BluetoothDevice tmp : devices) {
if (tmp.getAddress().equals(device.getAddress())) {
bIsExist = true;
break;
}
}
if (!bIsExist) {
devices.add(device);
}
}
}
}
click event
public void MainClickEvent(){
binding.btScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBleScanner.startScan(scanCallback);
}
});
binding.btStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mBleScanner.stopScan(scanCallback);
}
});
}
The test situation is repeated as Start -> Stop -> Start -> Stop.
Thank you.
question from:
https://stackoverflow.com/questions/65841470/error-due-to-frequent-calls-to-bluetooth-scan 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…