3

我们想通过蓝牙远程遥控机器人。现在我们正在使用 android 示例。我们想作为客户端连接。这部分之前的代码正在运行。现在我们得到一个错误:

manageConnectedSocket(mmSocket);

“方法未定义”。我们能做些什么来解决这个问题?感谢您的回答。

private class ConnectThread extends Thread {
    private final BluetoothSocket mmSocket;
    private final BluetoothDevice mmDevice;

    public ConnectThread(BluetoothDevice device) {
        // Use a temporary object that is later assigned to mmSocket,
        // because mmSocket is final
        BluetoothSocket tmp = null;
        mmDevice = device;

        // 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);
        } catch (IOException e) { }
        mmSocket = tmp;
    }

    public void run() {
        // Cancel discovery because it will slow down the connection
        mBluetoothAdapter.cancelDiscovery();

        try {
            // Connect the device through the socket. This will block
            // until it succeeds or throws an exception
            mmSocket.connect();
        } catch (IOException connectException) {
            // Unable to connect; close the socket and get out
            try {
                mmSocket.close();
            } catch (IOException closeException) { }
            return;
        }

        // Do work to manage the connection (in a separate thread)
        manageConnectedSocket(mmSocket);
    }

    /** Will cancel an in-progress connection, and close the socket */
    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) { }
    }
}
4

1 回答 1

4

据此manageConnectedSocket不存在。

manageConnectedSocket() 是应用程序中的一个虚构方法,它将启动用于传输数据的线程,这在有关管理连接的部分中进行了讨论。

而且您还没有在代码中定义它。您需要自己创建方法,或按照 Android 教程的其余部分进行操作。

于 2012-06-19T15:31:35.783 回答