Android SPP 蓝牙到非 Android 设备
我试图模仿 gilead 的成功(此处),但到目前为止他在我的应用程序中的代码失败了。我尝试了多个 UUID 但没有任何效果。当我运行 sdptool 记录 [地址] 时,我得到:
$ 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!");
...
}
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!");
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 BluetoothDevice createRfcommSocketToServiceRecord
According to BluetoothDevice createRfcommSocketToServiceRecord