Send Command to Bluetooth from Android device

后端 未结 3 1788
天命终不由人
天命终不由人 2021-01-07 19:52

I am getting a issue to send Commands from my android device to Bluetooth device.

Bluetooth is associated with a micro-controller. My effort is below:



        
相关标签:
3条回答
  • 2021-01-07 20:43

    I have a very simmilar code and it's working, maybe one of the main differences it that I'm doing a reset of threads:

    // Reset the ConnectThread because we're done
                synchronized (blablabla.this) {
                    mConnectThread = null;
                }
    
    // Cancel the thread that completed the connection
            if (mConnectThread != null) {
                mConnectThread.cancel();
                mConnectThread = null;
            }
    
        // Cancel any thread currently running a connection
        if (mConnectedThread != null) {
            mConnectedThread.cancel();
            mConnectedThread = null;
        }
    
        // Start the thread to manage the connection and perform transmissions
        mConnectedThread = new ConnectedThread(socket);
        mConnectedThread.start();
    

    Just after you do:

    mmSocket.connect();
    

    hope it helps.

    0 讨论(0)
  • 2021-01-07 20:47

    I tried this library. You can try it also https://github.com/palaima/AndroidSmoothBluetooth

    0 讨论(0)
  • 2021-01-07 20:50

    As you have mentioned that the issue is there on mmSocket.connect(); line hence, the problem is not while you are sending the command but creating a connection i.e. you are not able to retrieve a BluetoothSocket in opened or connected state.

    What should you do ?

    Try to use the below code with UUID , its valid for my bluetooth dongles.

    UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); createInsecureRfcommSocketToServiceRecord(MY_UUID)

    Let me know if this works for you.

    Also check, https://stackoverflow.com/a/18786701/1503130

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