Android How to - Sends an object through bluetooth








Question

We would like to know how to sends an object through bluetooth.

Answer

/*  w ww.j a  va 2s .c  om*/
import java.io.ObjectOutputStream;

import android.bluetooth.BluetoothSocket;
public class Main {
  
  
  /**
   * Sends an object through bluetooth.
   */
  public static boolean bluetoothWriteObject(Object object, BluetoothSocket socket) {
    try {
      ObjectOutputStream oOS = new ObjectOutputStream(socket.getOutputStream());
      oOS.writeObject(object);
      oOS.flush();
      return true;
    } catch (Exception e) {
      return false;
    }
  }
}