Send data from android bluetooth to PC with bluecove

前端 未结 2 1021
故里飘歌
故里飘歌 2020-12-14 22:42

I\'m trying to send data from android (using API from its SDK) to a PC using Bluecove on windows, being this last one the server.

I can get the android to connect t

相关标签:
2条回答
  • 2020-12-14 22:45

    Try with "println" instead of "write" in your Android sendData method !

    0 讨论(0)
  • 2020-12-14 22:50

    I have done similar thing 2 years ago.

    For Android, my code is slightly different from yours:

    BluetoothSocket socket = Device.createRfcommSocketToServiceRecord(device_UUID);
    socket.connect();
    DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
    
    dos.writeChar('x'); // for example
    
    socket.close();
    

    I used DataOutputStream to send data to PC. But surely this doesn't matter, just for your reference.

    For PC,

    LocalDevice localDevice = LocalDevice.getLocalDevice();
    
    localDevice.setDiscoverable(DiscoveryAgent.GIAC); // Advertising the service
    
    String url = "btspp://localhost:" + device_UUID + ";name=BlueToothServer";
    StreamConnectionNotifier server = (StreamConnectionNotifier) Connector.open(url);
    
    StreamConnection connection = server.acceptAndOpen(); // Wait until client connects
    //=== At this point, two devices should be connected ===//
    DataInputStream dis = connection.openDataInputStream();
    
    char c;
    while (true) {
        c = dis.readChar();
        if (c == 'x')
            break;
    }
    
    connection.close();
    

    I am not sure if the above codes still work today, as this was done 2 years ago. The BlueCove API may have changed a lot. But anyway, these codes work for me. Hope this may help you.

    One more note is that, I had to uninstall the Toshiba Bluetooth Driver in my PC and reinstall the Microsoft one in order to make use of BlueCove. Otherwise, it won't work. (However, latest version of BlueCove may have already supported different drivers, please correct me if I said anything wrong.)

    0 讨论(0)
提交回复
热议问题