send Data To Paired Bluetooth Device - Android Bluetooth

Android examples for Bluetooth:Bluetooth Bond

Description

send Data To Paired Bluetooth Device

Demo Code


//package com.java2s;
import android.bluetooth.BluetoothSocket;
import android.util.Log;
import java.io.IOException;
import java.io.OutputStream;

public class Main {
    public static void sendDataToPairedDevice(BluetoothSocket socket,
            String message) {/*from w  w  w  .ja  va2s .c  om*/
        byte[] toSend = message.getBytes();
        try {
            //BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(Constants.uuid);
            OutputStream mmOutStream = socket.getOutputStream();
            mmOutStream.write(toSend);
            // Your Data is sent to  BT connected paired device ENJOY.
        } catch (IOException e) {
            Log.e("BluetoothSend", "Exception during write", e);
        }

        Log.d("Sent to: ", socket.getRemoteDevice().getName() + ", "
                + message);
    }
}

Related Tutorials