Code example for BluetoothAdapter

Methods: listenUsingRfcommWithServiceRecord

0
  private Thread thread = new Thread(this, "Bluetooth server");
  private InputListener listener;
 
  BluetoothServerPort(BluetoothAdapter adapter, UUID uuid)
    throws IOException { 
    serverSocket = adapter.listenUsingRfcommWithServiceRecord("XCSoar", uuid);
 
    thread.start();
  } 
 
  @Override public void run() { 
    while (true) { 
      try { 
        BluetoothSocket socket = serverSocket.accept();
        Log.i(TAG, "Accepted Bluetooth connection from " +
              BluetoothHelper.getDisplayString(socket));
        BluetoothPort port = new BluetoothPort(socket);
 
        /* make writes non-blocking and potentially lossy, to avoid 
           blocking when one of the peers doesn't receive quickly 
           enough */