Android 蓝牙 在哪里可以获得 UUID?

发布于 2024-09-29 06:33:22 字数 259 浏览 6 评论 0原文

我想通过蓝牙连接 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

橪书 2024-10-06 06:33:22

如果您使用的是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.

岁月蹉跎了容颜 2024-10-06 06:33:22

UUId用于唯一标识应用程序。每个应用程序都有一个唯一的uuid。因此每个设备使用相同的uuid

UUid is used to uniquely identify applications.Each application have a unique uuid .so use the same uuid for each device

奢华的一滴泪 2024-10-06 06:33:22

为了连接目标设备,您需要知道要连接的是什么。列出您的设备目标会更有帮助。

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()

陌上芳菲 2024-10-06 06:33:22

您必须获取蓝牙 UUID 才能与设备建立连接,

您可以使用反射调用方法 getUuids()

    try {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
    ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);

         if(uuids != null) {
             for (ParcelUuid uuid : uuids) {
                 Log.d(TAG, "UUID: " + uuid.getUuid().toString());
             }
         }else{
             Log.d(TAG, "Uuids not found, be sure to enable Bluetooth!");
         }

    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }

不要忘记添加权限:

   <uses-permission android:name="android.permission.BLUETOOTH"/>

并且您必须启用蓝牙才能获取 Uuids,例如:

UUID: 0000110f-0000-1000-8000-00805f9b12fb
UUID: 0000111d-0000-1000-8000-00805f9b12fb
UUID: 0000111a-0000-1000-8000-00805f9b12fb

You must get the Bluetooth UUID to establish a connection to the device,

you can invoke the method getUuids() using reflection:

    try {
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    Method getUuidsMethod = BluetoothAdapter.class.getDeclaredMethod("getUuids", null);
    ParcelUuid[] uuids = (ParcelUuid[]) getUuidsMethod.invoke(adapter, null);

         if(uuids != null) {
             for (ParcelUuid uuid : uuids) {
                 Log.d(TAG, "UUID: " + uuid.getUuid().toString());
             }
         }else{
             Log.d(TAG, "Uuids not found, be sure to enable Bluetooth!");
         }

    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }

Don´t forget to add the permission:

   <uses-permission android:name="android.permission.BLUETOOTH"/>

and you must enable bluetooth to get Uuids, for example:

UUID: 0000110f-0000-1000-8000-00805f9b12fb
UUID: 0000111d-0000-1000-8000-00805f9b12fb
UUID: 0000111a-0000-1000-8000-00805f9b12fb
歌枕肩 2024-10-06 06:33:22

想象一下,您有一项或多项服务。每个服务都有自己的 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.

束缚m 2024-10-06 06:33:22

您必须对尝试连接的设备进行服务发现,获取它返回的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文