Android SPP bluetooth to non Android device
I'm trying to mimic the success of gilead (here) but so far his code in my app fails. I've tried multiple UUIDs but nothing works. When I run sdptool records [address]
I get:
$ sdptool records 00:12:F3:04:80:80
sdptool records 00:12:F3:04:80:80
Service Name: SPP
Service RecHandle: 0x10001
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 1
Failed to connect to SDP server on 00:12:F3:04:80:80: Connection timed out
It shows the device is on channel 1 so I don't understand why the code does not work. I'm running Android 2.1. I cannot access the other device in any way and while debugging tmpsock has all the correct values before .connect()
is called.
My code
public void test(BluetoothDevice d) throws Exception
{
BluetoothSocket tmpsock = null;
OutputStream out = null;
InputStream in = null;
int port = 1;
Method m = d.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
tmpsock = (BluetoothSocket)m.invoke(d, port);
Log.d(开发者_高级运维"BT", "CONNECTING!!!!");
tmpsock.connect();
Log.d("BT", "CONNECTED!");
...
}
According to BluetoothDevice createRfcommSocketToServiceRecord
If you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB.
精彩评论