title: Android to PC RFCOMM Channel
body: <p>So im working an an App that directly connect via Bluetooth to accept String commands from an RFCOMM channel and send responses.</p>
  
  <p>So those are the 2 Classes i am currently working with</p>
  
  <p><strong>Bluetooth_Manager</strong></p>
  
  <pre><code>import android.bluetooth.*;
  import android.content.Intent;
  
  public class Reader_BluetoothManager {
  
      protected Reader_MainScreen main;
      protected BluetoothAdapter bAdapter;
      private Reader_AcceptThread bAccept;
  
      public Reader_BluetoothManager(Reader_MainScreen main) {
          this.main = main;
          initiate();
      }
  
      public void initiate(){
          checkForBluetooth();
          enableBluetooth();
      }
  
      public void log(String l){
          main.log(l);
      }
  
      public void checkForBluetooth(){
          bAdapter = BluetoothAdapter.getDefaultAdapter();
          if (bAdapter == null) {
              main.log("No Bluetooth supported!");
              return;
          }
          main.log("Bluetooth supported...");
      }
  
      public void enableBluetooth(){
          if (!bAdapter.isEnabled()) {
              main.log("Bluetooth not enabled... requesting activation");
              Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
              main.startActivityForResult(enableBtIntent, main.BLUETOOTH_ENABLE_CODE);
          }
      }
  
      public void enableConnection(){
          main.log("Connecting...");
          if (bAccept != null)
              bAccept.interrupt();
          bAccept = new Reader_AcceptThread(this);
          bAccept.start();
      }
  
      public void stopConnection(){
          if (bAccept != null)
              bAccept.interrupt();
      }
  }
  </code></pre>
  
  <p>And <strong>AcceptThread</strong></p>
  
  <pre><code>import java.io.IOException;
  import java.util.UUID;
  
  import android.bluetooth.BluetoothDevice;
  import android.bluetooth.BluetoothServerSocket;
  import android.bluetooth.BluetoothSocket;
  
  public class Reader_AcceptThread extends Thread{
  
      private BluetoothServerSocket serverSocket;
      private BluetoothSocket socket;
      private BluetoothDevice device;
      private Reader_BluetoothManager main;
  
  
      public Reader_AcceptThread(Reader_BluetoothManager main) {
          this.main = main;
      }
  
      public void run(){
          try {
              serverSocket = main.bAdapter.listenUsingRfcommWithServiceRecord("XXXXXX", UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
              main.log("checkPoint 1");
              socket = serverSocket.accept();
              main.log("checkPoint 2");
              device = socket.getRemoteDevice();
              main.log("checkPoint 3");
              main.log("connection established...");
              main.log(socket.toString());
          } catch (IOException e) {
              main.log("error...");
              main.log(e.toString());
              main.main.stopConnection();
              interrupt();
          }
          while (!isInterrupted()){
              try {
                  sleep(2000);
              } catch (InterruptedException e) {
                  interrupt();
                  break;
              }
              main.log("ping");
          }
      }
  }
  </code></pre>
  
  <p>I constructed these according to the Google Docs Guide.
  Also on my Laptop i am doing the following:</p>
  
  <p><img src="https://i.stack.imgur.com/JY3Ek.png" alt="enter image description here"></p>
  
  <p>And this is, what is happening on my Phone:
  <img src="https://i.stack.imgur.com/Vp2eP.png" alt="enter image description here"></p>
  
  <p>Here is, what is happening, when im trying to connect from my Windows PC:
  <img src="https://i.stack.imgur.com/F7u20.png" alt="enter image description here"></p>
  
  <p>As you can see on the phones screenshot i am stuck at <code>socket = serverSocket.accept()</code>.</p>