2

I am trying to connect my Android phone to my Nokia phone. I can discover the Nokia phone through my Andorid application. I can create the socket successfully:

btSocket = device.createRfcommSocketToServiceRecord(MY_UUID);

But when I try to connect to the nokia phone there is an error in connection. I am trying to run this sample provided in the link below:

http://www.anddev.org/code-snippets-for-android-f33/serial-over-bluetooth-simple-test-client-t11106.html

And an error is occured when the code btSocket.connect() which is present in the onResume() method is executed:

Logcat:

D/BluetoothAdapter(  176): checkBluetoothAddress
E/THINBTCLIENT( 4738): ON RESUME: Exception during connect.
E/THINBTCLIENT( 4738): java.io.IOException: Service discovery failed
E/THINBTCLIENT( 4738):  at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377) 
E/THINBTCLIENT( 4738):  at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201)<br>
E/THINBTCLIENT( 4738):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)

And this is the UUID I am using:

private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");`

Kindly let me know where I am going wrong. I tried to look for help in Stackoverflow and on the internet in general, but no help was found.

Community
  • 1
  • 1
Gadenkan
  • 1,691
  • 2
  • 17
  • 29

1 Answers1

0

I used the solution found here: Service discovery failed exception using Bluetooth on Android

For some reason unclear to me, reflection works on some devices where the ordinary method doesn't work. Try this:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class} );
btSocket = (BluetoothSocket) m.invoke(device, 1);      
Community
  • 1
  • 1
joon
  • 832
  • 13
  • 31