-
Notifications
You must be signed in to change notification settings - Fork 14
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
onServicesDiscovered may not be handled correctly #23
Comments
Don't believe everything you read on Stackoverflow. In this case the article is clearly wrong. My implementation is definitely correct. |
Got it. I am debugging an interesting thing right now. When 2 android phones are both connected to each other (each device is a central and a peripheral) and I background and of the apps (which stops scanning/advertising and closes both the central manager and peripheral manager), onServicesDiscovered is getting triggered. |
I have been able to work around the issue by checking to see if the service is null or not. In the case where I am getting the erroneous callback, the service is null and I can ignore it. I was just trying to track down where it is coming from. Oddly enough, when disconnecting an iOS device I do not get the same behavior on the Android side. |
Android seems to have issues when it is both a central and peripheral at the same time. Never been able to find a workaround for that....let me know if you find something |
I have been able to workaround this issue by doing a simple check at the top of @Override
public void onServicesDiscovered(final BluetoothPeripheral peripheral) {
if (peripheral.getService(TARGET_SERVICE_UUID) == null) {
return;
}
... Essentially when this is called as a device disconnects, calling getService (for what I am expecting) will return |
Right, that may work indeed. I still haven't found a way to deal with the issue inside the library.... |
Android will call
onServicesDiscovered
multiple times as it is discovering a service and will only call it with a "Success" after it has finished fully discovering the service and all of its characteristics. This library incorrectly assumes if Success is not set then we should disconnect; however that just means Android isn't finished. This can be seen in this answer: https://stackoverflow.com/questions/72099997/android-ble-device-keep-disconnecting-after-a-succesfull-characteristic-writeThe text was updated successfully, but these errors were encountered: