android.bluetooth.BluetoothSocket cannot connect

后端 未结 1 1062
终归单人心
终归单人心 2021-02-11 04:05

I\'ve tried all the suggestions in other comments without avail and I hope someone can help me. I\'ve been struggling with this problem for three days now. I\'m quite sure my UU

相关标签:
1条回答
  • 2021-02-11 05:00

    Your code looks generally good, I assume you just copy and paste it from some examples.

    There is a bug in some Android phones such as HTC desire, which cause method device.createRfcommSocketToServiceRecord to fail. I would suggest following approach:

    1) Trying to chat between two linux computer using pythong scripts provided at http://www.radekdostal.com (you know where) by that you verify that your Linux setup is working properly.

    2) Trying to initiate connection from computer to Android (use android-bluetooth-chat-client-python) Be aware that default BluetoothChat demo is able to accept connection only on the first try.

    3) Try connecting from Android phone to linux computer, but manually specify RFCOMM channel number using following code

    // BUGBUG: Following code is not properly implemented on HTC DESIRE
    // mSocket =                  device.createRfcommSocketToServiceRecord(UUID.fromString("6a462dc0-703a-4bf3-a80e-a473a6332c64"));
    // WORKAROUND: Connecting directly to RFCOMM channel 1
    Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
    mSocket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1)); // 1==RFCOMM channel code 
    

    You will need to find out what is your RFCOMM channel number using

    # sdptool browse local
    
    0 讨论(0)
提交回复
热议问题