Question

I'm trying to read data from Bluetooth device, first I installed "S2 Bluetooth term3" which works very nice..

Now I'm trying to read data from my own application creating a socket so:

mSocket = device.createRfcommSocketToServiceRecord(device.getUuids()[0].getUuid());

But, doesn't work, I got this:

Service discovery failed

I've read several posts and I've tried this:

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

And I got this:

Permission denied

This fails on this line:

mSocket.connect();

The UUID of my device is: 00000111-0000-1000-8000-00805f9b34bf

Thanks.

Était-ce utile?

La solution

I got it, since Android 4.0.4 (API 10) is necessary to use:

createInsecureRfcommSocketToServiceRecord(...)

instead of:

createRfcommSocketToServiceRecord(...)

Now my app works!

Autres conseils

Do you have the proper permissions in the manifest?

`<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />`
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top