如何在Android编程中使用蓝牙不配对发送和接收数据? [英] How to send and receive data in Android Programming using bluetooth without pairing?

查看:46
本文介绍了如何在Android编程中使用蓝牙不配对发送和接收数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 编程的新手,并且有 java 概念,我想知道如何使用蓝牙发送和接收数据而无需配对或任何密码(仅当两台设备都安装了我的应用程序时),有什么建议吗?

I am new to Android programming, and have java concept, I want to know that how can I send and receive data using bluetooth without pairing or any password (Only if both device has my app installed), any suggestion?

推荐答案

据我所知,如果没有配对,就不可能通过 RFCOMM 套接字发送数据.我已经对我正在开发的应用程序进行了广泛的尝试.我的结果是:

As far as I know it's impossible to send or receive data over RFCOMM sockets without pairing. I've tried this extensively with an application that I'm developing. My results are:

  • 如果两台设备配对且可发现,则可以进行双向通信
  • 如果两个设备已配对,但服务器"设备(Android 设备尝试连接的那个)设置为不可发现,那么双向通信仍然是可能的
  • 如果两个设备未配对,但服务器"设备可发现,则在双向通信成为可能之前仍需要配对请求.这意味着 RFCOMM 客户端 套接字(即来自 Android 的套接字)需要设备配对.这是在运行 Android 2.2 的三星 Captivate 上进行的测试.我觉得这很奇怪,因为我可以理解在允许 RFCOMM 服务器套接字之前需要配对,但要求对客户端套接字进行配对有点严格.
  • If the two devices are paired and discoverable, bi-directional communication is possible
  • If the two devices are paired, but the "server" device (the one the android device is trying to connect to) is set to be not discoverable, then bi-directional communication is still possible
  • If the two devices are not paired, but the "server" device is discoverable, then a pairing request is still required before bi-directional communication is possible. This means that RFCOMM client sockets (i.e., those from Android) require the devices to be paired. This was tested on a Samsung Captivate running Android 2.2. I find this very strange, as I can understand requiring pairing before allowing RFCOMM server sockets, but requiring pairing for client sockets is a bit stringent.

正如@ethrbunny 提到的,你也可以只使用 WiFi,在每个设备上设置并行服务器/客户端线程,然后发送任何你想要的.要发现本地网络上的服务,您可以选择使用 zeroconf.

As @ethrbunny mentioned you can also just use WiFi, setup parallel server/client threads on each device, and send whatever you want. To discover services on a local network you can optionally use zeroconf.

这篇关于如何在Android编程中使用蓝牙不配对发送和接收数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆