title: Connect to Android Bluetooth socket
body: <p>Hi I am trying to create an Android app which will connect to a Blue SMiRF Bluetooth dongle which I want to send data to. I have read over the developer pages and looked at multiple different examples however I am currently having trouble creating a connection to the socket. The Bluetooth portion of the code is pretty much from an example that I was able to find. When trying to connect to the Bluetooth dongle the app gets a force close because there is some error I am not handling correctly. However I have also tried to use the app just to connect to another PC and the connection wont get established correctly for some reason even though I am already paired with the device through the Bluetooth settings before I even run the app. I have posted some of the more important code below for where I think my issue may be. Any help will be very appreciated, please let me know if I should post any additional code.</p>
  
  <pre><code>protected void connect(BluetoothDevice device) {
      //BluetoothSocket socket = null;
      try {
          //Create a Socket connection: need the server's UUID number of registered
  
          socket = device.createRfcommSocketToServiceRecord(UUID.fromString("a60f35f0-b93a-11de-8a39-08002009c666"));
  
  
  
          socket.connect();
          Log.d("EF-BTBee", "&gt;&gt;Client connectted");
  
          InputStream inputStream = socket.getInputStream();                                                      
          OutputStream outputStream = socket.getOutputStream();
          outputStream.write(new byte[] { (byte) 0xa0, 0, 7, 16, 0, 4, 0 });
  
  
          new Thread() {
              public void run() {
                      while(true)
                      {   
                      try {
                          Log.d("EF-BTBee", "&gt;&gt;Send data thread!");
                          OutputStream outputStream = socket.getOutputStream();
                          outputStream.write(new byte[] { (byte) 0xa2, 0, 7, 16, 0, 4, 0 });
                      } catch (IOException e) {
                          Log.e("EF-BTBee", "", e);
                      }
                      }
              };
          }.start();
  
      } catch (IOException e) {
          Log.e("EF-BTBee", "", e);
      } finally {
          if (socket != null) {
              try {
                  Log.d("EF-BTBee", "&gt;&gt;Client Close");
                  socket.close(); 
                  finish();
                  return ;
              } catch (IOException e) {
                  Log.e("EF-BTBee", "", e);
              }
          }
      }
  }`
  </code></pre>
  
  <p>I have also tried using </p>
  
  <pre><code>Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
  
          socket = (BluetoothSocket) m.invoke(device, 1);
  </code></pre>
  
  <p>instead of just the "socket =" line from above and still had no success.</p>