Bluetooth (classic Server and Client) IsConnected does not report disconnected state? Android 8

Hi,

does anybody else have a problem with Bluetooth Classic IsConnected function since ... today or yesterday (app. sept. 23. 2021) I think?
I can get it to report connected state but not disconnected.
An older .apk still works, todays AI Companion build does not.
That is on Android 8.

Cheers,
N

maybe something changed, in the meantime, you can use my extension

BluetoothInfo Extension [Free & Open Source]

the IsConnected property never was able to detect, that a connection is gone
see also Change Text when Bluetooth disconnected - #8 by Taifun

as the bluetooth protocol was designed, there is no way to detect, if a connection still is alive, therefore you have to send regularly (i.e. poll) some data to the device. And if you get an error, then you know, that the connection was lost…

see also A simple Bluetooth Chat with App Inventor 2

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Ha! Thanx! Yo saved me a lot of time.

My previous app version had me thinking IsConnected was working, while in fact it was error handling (Error 516) plus periodic sending of time sync data. So exactly:
"...therefore you have to send regularly (i.e. poll) some data to the device. And if you get an error, then you know, that the connection was lost…"

Yes, this an annoying implementation at the Android level. I've looked into the Android OSP code and the connected flag at the library level is just implemented as a boolean and isn't really reflective of the underlying hardware state. I wish we could provide a better experience but there's not much to work with.

Thank you for your reply.
A "client polling" solution together with error checking should solve this problem as suggested by Taifun. I "accidentaly" had that in my previous sketch and than broke it. :slight_smile: