Skip to content
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

BLE disconnect on Android issue #54

Open
iBog opened this issue Mar 13, 2024 · 6 comments
Open

BLE disconnect on Android issue #54

iBog opened this issue Mar 13, 2024 · 6 comments
Labels

Comments

@iBog
Copy link

iBog commented Mar 13, 2024

Trying to connect to BLE "HR monitor" device.
App should auto search all devices, found by name, connect, subscribe characteristic to notify every data change.
await CentralManager.instance.setCharacteristicNotifyState(
characteristic,
state: true,
);
All this steps working fine, data start flowing.

On app close (hide) - App should auto disconnect from device.
On this step I call two actions -

  1. await CentralManager.instance.setCharacteristicNotifyState(
    characteristic,
    state: false,
    );
    To stop characteristic subscription
  2. await CentralManager.instance.disconnect(peripheral);
    to disconnect from BLE device itself

After application Resume, need to start from the beginning: Search, Connect... but
BLE device not listed in search list anymore.
As I understand, connection with BLE not stopped, and device still attached.
If temporary switch OFF bluetooth on Android, and run Search BLE devices again - "HR monitor" appeared again,
because "pairing" was interrupted and device is ready to be searched and connected

Guide me what i did wrong, or package "bluetooth_low_energy" has an issue when App using CharacteristicNotify

@iBog
Copy link
Author

iBog commented Mar 13, 2024

small addition, BLE device is not switched off, it always on me and working,
flutter app should periodically connect to device and disconnect from it.

@yanshouwang
Copy link
Owner

yanshouwang commented Mar 14, 2024

Does the connection closed after you called disconnect method manully?

In my opinion, it's the system's duty to disconnect the BLE device when app closed, and our BLE device did disconnected when I close my app.

I found there some cases on the internet that the connection still connected after app closed, but I can't find anything useful...
https://stackoverflow.com/questions/73107781/devices-with-android-12-keep-bluetooth-le-connection-even-when-app-is-closed
evothings/cordova-ble#136

@iBog
Copy link
Author

iBog commented Mar 14, 2024

@yanshouwang according to connectionStateChanged, connectionState become false.
Agree with you, looks like system delay on releasing connection with device.
Also found solution in quick.blue library: https://github.com/pauldemarco/flutter_blue/issues/317#issuecomment-522134619

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Apr 14, 2024
Copy link

This issue was closed because it has been inactive for 14 days since being marked as stale.

@yanshouwang yanshouwang reopened this Aug 30, 2024
@github-actions github-actions bot removed the stale label Aug 30, 2024
Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants