user1487000
user1487000

Reputation: 1201

Sending character via bluetooth on Android?

I know how to send files by invoking the phone's native bluetooth settings and letting the user choose who to send to.

But let's say I want to send the character 'v' directly to a paired device. I know the device's name, and address. What is the best way to go about doing this?

Upvotes: 4

Views: 5238

Answers (1)

Shridutt Kothari
Shridutt Kothari

Reputation: 7394

You can do it in this way:

    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 above method like

sendDataToPairedDevice("text to send" ,bluetoothDevice);

thats it. thanks, enjoy buddy.

Upvotes: 6

Related Questions