I use the SPP profile to connect to my device:
Set<BluetoothDevice> devices = ba.getBondedDevices(); for(BluetoothDevice bd : devices) { String name = bd.getName(); if(name.equals("CELLMETER")) { try { BluetoothSocket bs = bd.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB")); bs.connect(); } catch (IOException e) { e.printStackTrace();
Everything looks fine, I created a function where I close the input output buffers and close the socket. But when the application fails or I terminate the application when breakpoints arrive, the socket does not close, even after I killed the process manually, and it is not available for a new connection from a new instance of the application.
What am I doing wrong? For each failure / debug operation, I have to restart the phone :(
This only appeared for Android 2.3.5 (Samsung 5830i) and Android 4.0.4 (Freelander P10). On my Android 4.2.1 (Galaxy Nexus), everything is fine after the emergency connection application closes automatically. (it seems because there is a new Bluetooth stack)
source share