Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 什么是蓝牙uuid?我怎么得到它?_Java_Android_Bluetooth - Fatal编程技术网

Java 什么是蓝牙uuid?我怎么得到它?

Java 什么是蓝牙uuid?我怎么得到它?,java,android,bluetooth,Java,Android,Bluetooth,我正在尝试用蓝牙将我的应用程序连接到服务器。 但是我不知道这个uuid是什么,我应该如何找到它 class ConnectThread extends Thread { private final BluetoothSocket mmSocket; private final BluetoothDevice mmDevice; // Get a BluetoothSocket to connect with the given Blue

我正在尝试用蓝牙将我的应用程序连接到服务器。 但是我不知道这个uuid是什么,我应该如何找到它

class ConnectThread extends Thread {

        private final BluetoothSocket mmSocket;
        private final BluetoothDevice mmDevice;

            // Get a BluetoothSocket to connect with the given BluetoothDevice
            try {
                // MY_UUID is the app's UUID string, also used by the server code
                tmp = device.createRfcommSocketToServiceRecord(MY_UUID);

///这给了我一个错误,我应该如何修复它?

如果您使用的是BluetoothChat源代码,请在文件BluetoothChatService.java中找到UUID,如下所示:

public class BluetoothChatService {
    .
    .
    // Unique UUID for this application
    private static final UUID MY_UUID_SECURE =
    UUID.fromString("fa87c0d0-afac-11de-8a39-0800200c9a66");
    private static final UUID MY_UUID_INSECURE = 
    UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66");
    .
    .

如何生成uuid?@appubala此讨论和其中的各种链接可能会帮助您了解uuid。此外,第二个链接虽然有点过时,但可能对初学者有所帮助。这是常见的uuid 00001101-0000-1000-8000-00805f9b34fb,这是什么fa87c0d0-afac-11de-8a39-0800200c9a66,您是如何生成此id的?@appubala BT有232个16b格式。您提到的UUID是基本UUID(128b格式,请参见000011001与00000000之间的差异)。带有服务UUID的基本UUID构成每个服务的完整UUID。此232之外的任何UUID都是自定义UUID。因此,上述代码片段中的UUID(来自BluetoothChat.java)是一个自定义UUID。如果您的应用程序涉及串行端口配置文件(SPP),则可能不需要新的UUID,您提到的UUID适用于此。@appubala抱歉,我从未使用过,但知道这一点。此外,谷歌“UUID生成器”可以看到许多网站提供UUID代码生成服务。还提供了许多有用的链接。