Android How to - Receives an object through bluetooth








Question

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

Answer

/*from   ww  w .  jav  a  2  s . co  m*/
import java.io.ObjectInputStream;

import android.bluetooth.BluetoothSocket;
public class Main {
  /**
   * Receives an object through bluetooth.
   */
  public static Object bluetoothReadObject(BluetoothSocket socket) {
    ObjectInputStream oIS;
    try {
      oIS = new ObjectInputStream(socket.getInputStream());
      Object object = oIS.readObject();
      return object;
    } catch (Exception e) {
      return null;
    }
  }
}