-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sometimes causing system Bluetooth to crash. #556
Comments
This is how I switch connections. Don't know what's the problem? Timeouts can easily occur after switching connections multiple times. Then the above problems will occur. private ConnectRequest connectRequest;
private void addDevice(BluetoothDevice device) {
new Thread(new Runnable() {
@Override
public void run() {
if (clientManager.isConnected()) {
try {
clientManager.disconnect().await();
clientManager.close();
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}
if (connectRequest != null) {
connectRequest.cancel();
}
connectRequest = clientManager.connect(device)
.useAutoConnect(true)
.retry(3, 0)
.timeout(20 * 1000);
connectRequest.enqueue();
}
}).start();
} |
Sorry, let me correct the description above. This error does not necessarily occur when the connection times out, because I just tested it and this error also occurs when the connection is in progress, and you can always see it when there is a problem.
|
So far I have tested 100% of the steps that trigger the problem. Triggering a rescan after connecting to the device or during the connection process can cause the above issues. |
This is my scanning code. Currently, this kind of thing only happens on some Android 9.0 devices. I tested another Android 7.0 device. It was connecting or connected. It was normal when I rescanned it. With my scan settings, it might be possible. does it matter? private void startScan() {
if (!PermissionUtils.isGpsEnabled(requireContext())) {
showGpsRequestReasonDialog();
return;
}
Log.e(TAG, "startScan: ---");
binding.mSrLayout.setRefreshing(true);
mDeviceAdapter.setNewData(getConnectedDevices());
final BluetoothLeScannerCompat scanner = BluetoothLeScannerCompat.getScanner();
final ScanSettings settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.setReportDelay(5000)
.setUseHardwareBatchingIfSupported(false)
.setUseHardwareFilteringIfSupported(false)
.build();
final List<ScanFilter> filters = new ArrayList<>();
filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(HEART_RATE_SERVICE_UUID)).build());
scanner.startScan(filters, settings, scanCallback);
scanning = true;
handler.removeCallbacks(stopScanRunnable);
handler.postDelayed(stopScanRunnable, SCAN_DURATION);
} |
This happens when switching connections between multiple heartbeat devices. Please help me take a look, thank you!
I'm using
implementation("no.nordicsemi.android:ble:2.7.4")
This is my error log:
The text was updated successfully, but these errors were encountered: