Android 蓝牙 在哪里可以获得 UUID?
我想通过蓝牙连接 3 个设备。
例如我使用BluetoothChat。那么我如何理解我应该为此设备使用不同的 UUID。我一直在尝试通过这样的 UUID=766c82f0-e1b4-11df-85ca-0800200c9a66 进行连接,这是我从 Web UUID 生成器获得的。但这根本不起作用。
如果我使用 UUID=00001101-0000-1000-8000-00805F9B34FB,我已成功连接(至 1 台设备)
我在哪里可以获得 UUID?
I want to connect 3 devices via Bluetooth.
As for example I use BluetoothChat. So How I understand I should use different UUID for this devices. I have been trying to connect via such UUID=766c82f0-e1b4-11df-85ca-0800200c9a66, which I 've get it from Web UUID generator. But it doesn't work at all.
I have succesfully connected (to 1 device) if I used UUID=00001101-0000-1000-8000-00805F9B34FB
Where can I get UUID?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您使用的是linux或mac,在终端中输入“uuidgen”这个不带引号的命令,您将获得一个唯一的UUID,在您的android项目中使用它。
if you are using linux or mac, enter "uuidgen" this command without quotes in terminal, you will get an unique UUID, use that in your android project.
UUId用于唯一标识应用程序。每个应用程序都有一个唯一的uuid。因此每个设备使用相同的uuid
UUid is used to uniquely identify applications.Each application have a unique uuid .so use the same uuid for each device
为了连接目标设备,您需要知道要连接的是什么。列出您的设备目标会更有帮助。
UUID 可以从此链接获取,http://www.bluecove。 org/bluecove/apidocs/javax/bluetooth/UUID.html
在这里,您需要知道每个目标设备正在使用什么蓝牙配置文件。您提到“UUID=00001101-0000-1000-8000-00805F9B34FB”有效。
这是因为您的设备具有 SPP 蓝牙配置文件。 SPP 代表串行端口配置文件。
您还可以在 Bluetoothdevice.getuuids 上查找
http://developer.android.com/reference/android/bluetooth /BluetoothDevice.html#getUuids()
In order to connect with your targetted devices, you need to know what are you connecting to. It'll be more helpful to list your device targets.
The UUID can be obtained from this link, http://www.bluecove.org/bluecove/apidocs/javax/bluetooth/UUID.html
Here you need to know what bluetooth profile is being used in each of your target device. You mentioned that "UUID=00001101-0000-1000-8000-00805F9B34FB" works.
This is due to your device is having a SPP Bluetooth profile. SPP stands for Serial Port Profile.
You could also lookup on Bluetoothdevice.getuuids
http://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#getUuids()
您必须获取蓝牙 UUID 才能与设备建立连接,
您可以使用反射调用方法
getUuids()
:不要忘记添加权限:
并且您必须启用蓝牙才能获取 Uuids,例如:
You must get the Bluetooth UUID to establish a connection to the device,
you can invoke the method
getUuids()
using reflection:Don´t forget to add the permission:
and you must enable bluetooth to get Uuids, for example:
想象一下,您有一项或多项服务。每个服务都有自己的 UUID。
UUID=00001101-0000-1000-8000-00805F9B34FB 是 SPP 专用的。如果不设置SPP UUID,某些设备(例如蓝牙串口板)将无法工作。
但对于 Android 设备(例如智能手机)之间的点对点连接,您可以使用自己生成的 UUID。
设备必须设置相同的 UUID 才能找到彼此并连接。
UUID 格式:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,其中 x=[0,...,9]|[A,...,F]。
好主意是将 xxxxxxxx-xxxx-xxxx-xxxx- 设置为您生成的唯一 ID。
第二部分 xxxxxxxxxxxx 可以设置为您的服务器 MAC 地址,不带“:”。
在客户端,您可以从已知生成的唯一 ID(嵌入到您的应用程序中)和服务器 MAC 地址构造 UUID(不带“:”)。您可以在蓝牙设备发现过程中获取服务器MAC地址。
Imagine, that u have a one or more services. Each service have its own UUID.
UUID=00001101-0000-1000-8000-00805F9B34FB is special one for SPP. Some devices (for example, Bluetooth serial board) will not work if u not set SPP UUID.
But for peer-to-peer connection between Android devices such as smartphones u may use your own generated UUID.
Devices must set same UUID to found each other and connect.
UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where x=[0,...,9]|[A,...,F].
Good idea is to set xxxxxxxx-xxxx-xxxx-xxxx- to Your generated unique id.
Second part xxxxxxxxxxxx may be set to Your server MAC address without ":".
On client side u may construct UUID from known generated unique id (embedded to Your app) and server MAC address without ":". You can get server MAC address during Bluetooth device discovery.
您必须对尝试连接的设备进行服务发现,获取它返回的 UUID(这将对应于设备上运行并接受连接的服务),然后连接到它。
you have to do a service discovery with the device you are trying to connect with, Get the UUID that it returns (which will be corresponding to the service that is running on the device and accepting connections) and then connect to it.