Android:蓝牙无法连接

时间:2016-01-29 03:31:29

标签: java android bluetooth

将Android平板电脑(5.0.1)连接到蓝牙芯片模块时遇到问题。问题是平板电脑无法连接,但蓝牙模块表示它已连接。

我的代码是:

private UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
public synchronized void run() {
    try {
        mySocket = btDevice.createInsecureRfcommSocketToServiceRecord(uuid);

    } catch (IOException createSocketException) {
        // Problem with creating a socket
        Log.e(EXCP_LOG, "exception", createSocketException);
    }
    // Cancel discovery on Bluetooth Adapter to prevent slow connection
    btAdapter.cancelDiscovery();


    try {
        Log.d("BLUETOOTH_DEBUG", "Attempting to connect");
        mySocket.connect();
        isConnected = true;

    } catch (IOException connectException) {
        Log.d("BLUETOOTH_DEBUG", "Connect thread exception");
        connectException.printStackTrace();

    }
    mHandler.obtainMessage(CONNECTED).sendToTarget(); 
}

logcat打印出来是:

W/BluetoothSocket: readAll() looping, read partial size: 11, expect size: 16
W/System.err: java.io.IOException: Connection failure, wrong signal size: 7
W/System.err:     at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:503)
W/System.err:     at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:327)
W/System.err:     at bluetoothpackage.ConnectToBluetooth.run(ConnectToBluetooth.java:72)
W/System.err:     at java.lang.Thread.run(Thread.java:818)

其中ConnectToBluetooth.java是上面的代码,第72行是mySocket.connect()命令。

对此的任何帮助将不胜感激

0 个答案:

没有答案