Android上如何通过蓝牙广播信息?
我想知道如何在Android上使用蓝牙广播信息。
我正在考虑在listenUsingRfcommWithServiceRecord()中利用SDP记录的服务名称来广播信息。但是,我找不到任何方法来读取 SDP 记录的服务名称。我可以知道有什么办法可以阅读吗?
或者还有其他更合适的方法来通过蓝牙广播信息吗?如果你知道请告诉我。我的项目确实需要快速了解这一点。我们将不胜感激您的帮助。 =)
I'd like to know how to broadcast information with Bluetooth on Android.
I'm thinking to utilize the service name for SDP record in listenUsingRfcommWithServiceRecord() to broadcast the information. However, I couldn't find any method to use to read the service name for SDP record. May I know is there any way to read that?
Or is there any other more appropriate approaches to broadcast information with Bluetooth? Plz enlighten me if u know. Really need to know this fast for my project. Ur help would be greatly appreciated. =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,Android 蓝牙 API 没有提供公共方法来获取已发现服务的名称。它也不提供获取目标设备上正在运行的服务的 UUID 的方法。然而,在开发我自己的应用程序时,我发现 这篇文章 详细介绍了访问隐藏方法以提供 UUID 所需的步骤。当然,不支持使用私有 API,等等,但我能够让它在我的应用程序中工作。话虽如此,我决定不使用私有 API,而只是尝试连接到我想要的服务(使用我的特定 UUID),捕获连接尝试中的任何错误。
Unfortunately the Android Bluetooth API doesn't provide a public method for getting the names of discovered services. Nor does it provide a way to get the UUIDs of running services on a target device. However, when developing my own application I found this post which details the steps necessary to get access to hidden methods to provide the UUIDs. Of course using private APIs is not supported, etc., etc., but I was able to get it to work in my app. With that said, I decided against using the private APIs and rather just try and connect to my desired service (with my specific UUID), catching any errors in the connection attempt.