通过蓝牙检测附近的另一台 Android 设备
好吧,我这里有一个有点奇怪的问题。我正在开发一款 Android 游戏,我希望 Android 手机能够检测到彼此的存在。
搜索其他玩家的设备将知道其他玩家设备的蓝牙 MAC 地址(来自游戏数据库),但是设备不会配对,并且设备不会处于可发现模式。此外,只能找到少数设备 - 因此扫描 MAC 地址并不是什么大问题。
我不需要连接到设备,我只需要能够回答一个简单的问题:该设备附近是否有该 MAC 地址?
允许在其他用户的屏幕上出现配对对话框...我不在乎他们选择的结果是什么...我只需要知道他们的设备是否在那里。
任何帮助将不胜感激!
Alright, I've got a bit of a weird question here. I'm working on an Android game where I'd like to be able to have Android phones detect the presence of each other.
The device searching for other players will know the bluetooth mac addresses of the other players' devices (from a game DB), however the devices will not be paired and the devices will not be in discoverable mode. Also, there will only be a handful of devices that could possibly be found - so it's not a big deal to scan through mac addresses.
I don't need to connect to the devices, I just need to be able to answer one simple question: is this device with this mac address nearby?
It is permissible to have a pairing dialog appear on the other user's screen...I don't care what the outcome of their choice is...I just need to know if their device is there.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此用例可能非常适合最近发布的 Nearby API。查看附近消息开发者概述
附近有自己的运行时权限,使您无需添加 BLUETOOTH_ADMIN 或类似内容到您的清单。它利用多种技术(经典蓝牙、BLE、超声波)在 iOS 和 Android 上运行。可以选择仅使用超声波调制解调器,从而将范围缩小到约 5 英尺。
我在下面提供了部分示例,您可以在 github
免责声明 I使用附近 API
This use-case may be a good fit for the recently released Nearby API. See the Nearby Messages developer overview
Nearby has its own runtime permission saving you from adding BLUETOOTH_ADMIN or similar to your manifest. It works across iOS and Android by utilizing multiple technologies (Classic Bluetooth, BLE, ultrasound). There's an option to use only the ultrasonic modem which reduces the range to about 5 feet.
I've included a partial example below, you can find a more complete sample on github
Disclaimer I work on the Nearby API