Android SPP 蓝牙到非 Android 设备

发布于 2024-09-02 15:31:55 字数 1029 浏览 5 评论 0原文

我试图模仿 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2024-09-09 15:31:55

根据 BluetoothDevice createRfcommSocketToServiceRecord

如果您要连接到蓝牙串行板,请尝试使用
著名的 SPP UUID 00001101-0000-1000-8000-00805F9B34FB。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文