Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.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,所以我想用android手机连接蓝牙模块(RN-42)。 我知道MAC地址,但我对UUID知之甚少。首先,我是否需要连接到的设备的UUID,或者我是否给了该设备我手机的UUID 现在我的代码是这样的: BluetoothDevice device = bluetooth.getRemoteDevice("00:06:66:43:40:70"); BluetoothSocket tmp = null;

所以我想用android手机连接蓝牙模块(RN-42)。 我知道MAC地址,但我对UUID知之甚少。首先,我是否需要连接到的设备的UUID,或者我是否给了该设备我手机的UUID

现在我的代码是这样的:

 BluetoothDevice device = bluetooth.getRemoteDevice("00:06:66:43:40:70");
                        BluetoothSocket tmp = null;
                        BluetoothSocket mmSocket = null;

                        try {
                            tmp = device.createRfcommSocketToServiceRecord(UUID);
                        } catch (IOException e) {
                            output = "Connecting to device failed!\n" + output;
                            if (output.length() > maxOutputLenght) {
                                output = output.substring(0, maxOutputLenght);
                            }
                            editText.setText(outputStart + output);
                        }
                        mmSocket = tmp;

                        try
                        {
                            mmSocket.connect();
                        } catch (IOException e)
                        {
                            output = "Connect() error\n" + output;
                            if (output.length() > maxOutputLenght) {
                                output = output.substring(0, maxOutputLenght);
                            }
                            editText.setText(outputStart + output);
                            error = true;
                        }

                        if(!error) {
                            changeScreen(1);
                        }
                        else
                        {
                            output = "Failure :C\n" + output;
                            if (output.length() > maxOutputLenght) {
                                output = output.substring(0, maxOutputLenght);
                            }
                            editText.setText(outputStart + output);
                        }

其目的是通过蓝牙模块将数据从我的android应用程序发送到picaxe处理器,从而控制RC汽车。它有一个我已经写过的程序,根据它接收到的数据控制汽车。

好的,整个问题是我不完全理解如何获取UUID以及使用什么UUID。所以我使用的是手机UUID(我猜)。我是如何通过这句话得到它的:

UUID UUID=device.getUuids()[0].getUuid()

感谢: