Giter VIP home page Giter VIP logo

Comments (5)

al-broco avatar al-broco commented on July 17, 2024 1

I have now, the fix seems to have solved the problem. I have run the same test with the new code 50 times, no issues, connection works beautifully. Thanks again!

from android-ble-library.

philips77 avatar philips77 commented on July 17, 2024

Thank you for the feedback. I can't do anything about the extra onConnectionStateChangeSafe, as it's being called by the system, but the lib should not get stack when it's called. Expect a fix soon.

from android-ble-library.

philips77 avatar philips77 commented on July 17, 2024

From my experience this happens when Android receives a notification after the disconnect() was called. First it notifies you that it's disconnected, but when it gets the notification it's like "hmm.. I'm still connected, so here's your callback with connected state".
What phone are you using for testing and how often a) you send notifications from the peripheral b) you experience this issue? You are not using autoConnect, right?

There are 2 solutions that can be done here:

  1. In onConnectionStateChangedSafe, where status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED, and mBluetoothDevice == null I may call gatt.close() before setting mConnected to true and pretend that it never happened. After all, you called disconnect(), so the desire effect is to be disconnected.
  2. I may try to recover to a state from before disconnection: mBluetoothDevice = gatt.getDevice(), mBluetoothGatt = gatt , and mGattCallbacks = this. But I'd have to register the receivers again, as close() was called before.

Looks like 1. is a better solution.

from android-ble-library.

al-broco avatar al-broco commented on July 17, 2024

Thanks for the quick fix! Here's the info you asked for:
Phone used for testing: Google Pixel with Android 7.1.2.
a. When doing this test, constantly. The peripheral is trying to stream data by repeatedly writing a characteristic.
b. Fairly frequently, maybe after 20% of the disconnects (rough approximation). No, I am not using autoConnect.

from android-ble-library.

philips77 avatar philips77 commented on July 17, 2024

By any chance, did you try the version from referenced PR?

from android-ble-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.