Android Bluetooth Connection - Service Discovery Failed

大憨熊 提交于 2019-11-29 04:23:59

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.

Its working for me

BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
socket = (BluetoothSocket) m.invoke(device, 1);
bluetoothAdapter.cancelDiscovery();
socket.connect();
Prasanth

The following code snippet works for me. Try it...

BluetoothDevice mmDevice;
boolean temp = mmDevice.fetchUuidsWithSdp();
UUID uuid = null;
if( temp ){
uuid = mmDevice.getUuids()[0].getUuid();
}
tmp = device.createRfcommSocketToServiceRecord(uuid);

I worked through a similar learning process. I have tried to document what I learned in a series of examples.

This one might be of help:

http://digitalhacksblog.blogspot.com/2012/05/android-example-bluetooth-simple-spp.html

It is for setting up a simple connection between an Android device and a PC via bluetooth. The examples contain the Android files as well as an SPP server in java and one in perl for the PC.

Hope this helps.

user1202714

Make sure that your app is not trying to connect while the adapter is busy with discovery: It appears the problem was that before I called

clientSocket.connect()

I needed to call

btAdapter.cancelDiscovery()

This helped solve the same problem for me Matts Reco

You'll have to provide a valid UUID for the service discovery.

BluetoothSocket sock = bdevice.createRfcommSocketToServiceRecord(VALID_UUID);

There are several common UUIDs for various standard (default) bluetooth services (Handsfree, File transfer, etc).

See here

Try using the Bluetooth Chat sample project provided as a part of the SDK if you are just trying to test the device. That code you're trying to use and the one provided on developer.android.com are included in the Bluetooth Chat example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!