安卓蓝牙
如果我想通过蓝牙连接到另一个设备,我该怎么做?
我所做的一切似乎都不起作用。我尝试连接的手机不是 Android 手机,并且已打开蓝牙且可发现。
If I wanted to connect to another device via bluetooth how would I do it?
Nothing I've done seems to work. The phone I'm trying to connect to is non android and has bluetooth on and discoverable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这种情况下,蓝牙 API 真的很差......让我们看看 java-doc:
来自: 链接文本
根据为此,您的对等点应该在
00001101-0000-1000-8000-00805F9B34FB
服务记录下可见。Bluetooth API is realy poor in this case... let's have look at java-doc:
from: link text
According to this, your peer should be visible under the
00001101-0000-1000-8000-00805F9B34FB
service record.现在,如果您想创建一个需要连接到蓝牙设备的应用程序,我建议您使用 Cordova 平台并安装一个插件,让您可以通过蓝牙连接、列出设备、发送数据、断开连接等...
Now, if you want to create an app which need to connect to Bluetooth devices, I advice you to use Cordova platform and install a plugin that let you connect via bluetooth, list devices, send data, disconnect etc...
在蓝牙中,存在应用层服务配置文件的概念。对等点 1 上愿意与对等点 2 上的同一应用程序进行通信的应用程序必须是可发现和可连接的,且由主设备发起连接。
该应用程序被赋予唯一的服务/应用程序标识符,以便对等点可以互相发现。如果您自己编写自定义应用程序,则需要创建一个新的 UUID,以便相应的 SDP 协议可以执行必要的发现。
您实际上可以通过优雅的服务发现来启动连接,而不是使用 BT_ADDR 进行强力连接,然后在识别出底层 UUID 后进行连接。当然,这是假设您提前完成了配对过程,或者您的较低层堆栈也将包括配对过程。
In Bluetooth, there is a concept of service profile for an application layer. An application on a peer 1 willing to talk to same application on peer 2 must be discoverable and connectable, the master initiating the connection.
The application is given a unique service/application identifier so that peers can discover each other. If you write a custom application yourself, you are expected to create a new UUID so that the corresponding SDP protocol can perform the necessary discovery.
Instead of connecting with brute force using the BT_ADDR, you would essentially initiate connection via graceful service discovery and then connection follows once the underlying UUID is identified. This, of course, assumes that you would have done the pairing process early, or that your lower layer stack will include pairing process as well.