2
我试图模仿gilead的成功(here),但到目前为止他的代码在我的应用程序中失败。我试过多个UUID,但没有任何作用。当我运行sdptool records [address]
我得到:Android SPP蓝牙到非Android设备
$ 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
它显示设备上的通道1,所以我不明白为什么代码不能正常工作。我正在运行Android 2.1。我无法以任何方式访问其他设备,并且在调试tmpsock在调用.connect()
之前具有所有正确的值。
我的代码
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!");
...
}