i'm writting an app which sends byte codes from a tablet to a µ-controler. Everything worked fine on the Lenovo A1 (Androi 2.3) and Samsung Galaxy Tab 7 Plus N (Android 3.2). Now i'm having issues with the new Samsung Galaxy Tab 2 (Android 4.0).
I'm able to pair with the Bluetooth antenna (which is connected to the µ-controller and communicates over the serial protocol). When I start the app I'm asked again to enter the password and to pair. After I enter the pairing password my main layout is visible but a connection isn't established.
The LogCat in eclipse tells me:
06-19 16:00:20.656: V/BluetoothSocket.cpp(3189): availableNative
06-19 16:00:20.664: V/BluetoothSocket.cpp(3189): abortNative
06-19 16:00:20.664: V/BluetoothSocket.cpp(3189): ...asocket_abort(49) complete
06-19 16:00:20.664: I/ActivityManager(185): No longer want com.google.android.partnersetup (pid 3220): hidden #16
06-19 16:00:20.671: V/BluetoothSocket.cpp(3189): availableNative
06-19 16:00:20.671: V/BluetoothSocket.cpp(3189): destroyNative
06-19 16:00:20.671: V/BluetoothSocket.cpp(3189): ...asocket_destroy(49) complete
06-19 16:00:20.679: D/KeyguardViewMediator(185): setHidden false
06-19 16:00:20.679: W/System.err(3189): java.io.IOException: socket closed
06-19 16:00:20.679: W/System.err(3189): at android.bluetooth.BluetoothSocket.available(BluetoothSocket.java:370)
06-19 16:00:20.679: W/System.err(3189): at android.bluetooth.BluetoothInputStream.available(BluetoothInputStream.java:40)
06-19 16:00:20.679: W/System.err(3189): at java.io.BufferedInputStream.available(BufferedInputStream.java:114)
06-19 16:00:20.687: W/System.err(3189): at ebs.alphadidact.control.ReceiveThread.run(ReceiveThread.java:79)
Further more is the LogCat receiving a thousand times the message:
V/BluetoothSocket.cpp(3189): availableNative
So as I searched in the web i found a few guys with a similar problem but no solution. Does someone know something about this issue?
Maybe it is a compability problem between the antenna and android 4.0. I don't think that the error is in my code because as I said the same code is running on older android versions perfectly.
Thanks to @fuentessifuentes answer i wrote this method including backwards compatibility:
Maybe it helps somone, out of this issu.
Ok, I found out what the problem is. I'm not sure if it is just a Samsung problem or an Android ICS problem.
I tried to connect to the antenna as usual by using (to get the Socket):
Well it seems that it doesn't work out with my antenna and Tablet setup, so I tried:
This does work. Ther first option forced the system to unpair the antenna and later ask for pairing again.
Actually creating an insecure socket is the same as connecting two unpaired devices. This is clearly not the best way to handle it.
I have found that Android tries to repair to the device, and then it rejects the pairing response. After this bizzare behavior, it will accept the next connection attempt!
I also tried the Android bugtracker: Bluetooth RFCOMM Server Socket no longer connects properly to embedded device on ICS 4.0.3.
Still waiting for a response...
I believe I am seeing the same problem. I am using an spp terminal app from Google play that worked perfectly after pairing the device with my stock droid x. But now with my galaxy s3 with the same app and same device requires me to re-pair every time.
Your solution is kind of a workaround. It seems android changed this behavior in ICS. So the real fix is for Google to fix ICS to allow spp devices to pair and connect without 're pairing.
But, I did see some code to address a similar issue:
Using this code:
and adding the following to our app Manifest worked
<uses-sdk android:minSdkVersion="13" android:targetSdkVersion="16"/>