Android Question error android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord

sanduro

Member
Licensed User
Longtime User
Hi.

I have a BT communication using async stream with prefix mode to communicate with microntroller control box.

I took me a while to "HACK" the commucation. After a while i totally gave up to fix any async stream errors they might pop up. Communication is now runs in separate process and whenever i expierence any problem, i just simply kill the process, restart control box streaming and start communication process again.

When i am killing the process i try to clean and sweep after myself. e,g,

Asyx.Close
Ser.StopListening
TimSer.Enabled = False
Ser.Disconnect

Problem is, from time to time my app stops in serial.connect command returns error
at android.bluetooth.BluetoothAdapter.createNewRfcommSocketAndRecord(BluetoothAdapter.java:1035)

whenever this happens, i can not start my application again, sometimes i can not even turn off bluetooth.
It looks like SERIAL still hangs on BT connetion and never release it.

Only solution is to reboot the tablet, and my app happily starts again.

Anybody expierenced similar problem or might enlighten me and send me the right way ?
Trouble is this error is very hard to reproduce when i try on purpose. It is one of those errors they start with SOMETIMES ....

I woudnt be bothered if it is some stupid chat app, but this should control the big seeding machine out on fields.

Thank you
San
 

sanduro

Member
Licensed User
Longtime User
I dug up some info on this, problem is that some android version keep the socket on bluetooth, even when your app is dead.

It is also some limit on how many sockets are available, if you run out of them your BT might die and you have to reboot android to fix it.

Only workaround i have found on web is to turn off and turn on BT adapter before it happens.

hmmm, i continue digging
 
Upvote 0
Top