3

为了以编程方式将数据发送到另一个蓝牙设备,我使用蓝牙套接字代码。每当我调用 bluetoothSocket.connect(); 它给出连接被拒绝或连接到对等异常。我对必须在其中使用哪个 UUId 或从哪里获得它感到困惑。下面是代码片段。

public void openBT() {
        UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); // Standard
                                                                                // SerialPortService

        try {

            mmSocket = mmDevice.createInsecureRfcommSocketToServiceRecord(uuid);
            Method m = mmDevice.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
            mmSocket = (BluetoothSocket) m.invoke(mmDevice, 3);
            mBluetoothAdapter.cancelDiscovery();
            mmSocket.connect();
            /*mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);

            mmSocket.connect();*/
            mmOutputStream = mmSocket.getOutputStream();
            mmInputStream = mmSocket.getInputStream();

            beginListenForData();

            myLabel.setText("Bluetooth Opened");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

帮助赞赏..!!

4

0 回答 0