Service Discovery Failed Exception Using Bluetooth on Android

Service discovery failed exception using Bluetooth on Android

After three days I got it figured out thanks to some very helpful posts.

I had to replace:

tmp = device.createRfcommSocketToServiceRecord(MY_UUID);

with:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);

and voilà it works!

Android Bluetooth Connection - Service Discovery Failed

I don't know and I still don't understand the UUID stuff but the problem was the UUID. I'm using the UUID which I got from the kernel logs and it is 00001105-0000-1000-8000-00805F9B34FB.

Android Bluetooth: java.io.IOException: Service discovery failed

Maybe you can try adding thread.sleep for a second? See this discussion:

"The only way I've been able to fix the problem is by adding a
thread.sleep for a second before closing the connection."

also see dan's two consecutive comments on this thread:

"I was able to get this to run only after separating the calls to
findBT(); openBT();

Otherwise, mmSocket.connect(); throws an exception, “Service discovery
failed”

but if I put findBT() in onCreate() and just use the button for
openBT(); it works fine.

Or, if I make a second button, one for each, it works fine.

Suggestions?"

the excerpts from the second comment:

Set pairedDevices = mBluetoothAdapter.getBondedDevices();
mmDevice = mBluetoothAdapter.getRemoteDevice(“00:06:66:46:5A:91″);
if (pairedDevices.contains(mmDevice))
{
statusText.setText(“Bluetooth Device Found, address: ” + mmDevice.getAddress() );
Log.d(“ArduinoBT”, “BT is paired”);
}

where I entered the address of my Bluetooth device. The original code
finds the device and returns the correct address, but
mmSocket.connect(); generates an exception “java.io.IOException:
Service discovery failed”

Suggestions?

Connect to a bluetooth device, exception: Service discovery failed

you can use this code:Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
mySocket = (BluetoothSocket) m.invoke(device, 1);



Related Topics



Leave a reply



Submit