1

I'm working on an app that connects to various Bluetooth printers. It works most of the time. However, if the app ever crashes or is killed via ADB without properly closing its BluetoothSocket, it cannot re-establish the socket when the app is restarted. It always fails with a particular exception message:

java.io.IOException: [JSR82] connect: Connection is not created (failed or aborted).

The only way I have found to clear this condition is to reboot the tablet and/or the device it's connected to. Is there another way? Hopefully the app won't crash so much when it's finished, but I'd still like it to be resilient.

I'm seeing this on a Lenovo tablet running 4.0.4, but I need to support devices as old as 2.3 and maybe 2.2.

Brodo Fraggins
  • 628
  • 5
  • 14
  • I found this discussion: http://stackoverflow.com/questions/14280623/android-bluetooth-connection-doesnt-close-after-application-crash – Brodo Fraggins Apr 11 '13 at 16:24
  • 1
    Following up on my own question: I solved this problem by letting my BluetoothSockets be managed by a Service that runs in its own process. I open, close, read, and write the sockets by passing Messages to and from the Service. If the app crashes, the Service shuts down cleanly. (It doesn't if it's running in the same process.) – Brodo Fraggins Jul 17 '13 at 00:15

0 Answers0