Sending a character over bluetooth on Android?

I know how to send files by calling up the phone's native Bluetooth settings and letting the user choose who to send.

But let's say I want to send the 'v' character directly to the paired device. I know the device name and address. What's the best way to do this?

+3


source to share


1 answer


You can do it like this:

    private void sendDataToPairedDevice(String message ,BluetoothDevice device){       
           byte[] toSend = message.getBytes();
            try {
                UUID applicationUUID = UUID.fromString("8ce255c0-200a-11e0-ac64-0800200c9a66");
                BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(applicationUUID);
                OutputStream mmOutStream = socket.getOutputStream();
                mmOutStream.write(toSend);
                // Your Data is sent to  BT connected paired device ENJOY.
            } catch (IOException e) {
                Log.e(TAG, "Exception during write", e);
            }
        }

      

Now call the method above like



sendDataToPairedDevice("text to send" ,bluetoothDevice);

      

here it is. thanks, enjoy buddy.

+5


source







All Articles