title: Not able to connect a Bluetooth Keyboard to an android device
body: <p>I am trying to programmatically connect an Android phone to a Bluetooth device (which is already paired). I am using <strong>createRfcommSocketToServiceRecord(UUID)</strong> method in a thread.</p>
  
  <p>I know the <strong>Bluetooth keyboard is a HID device</strong> so I am using UUID as </p>
  
  <blockquote>
    <p><strong>00001124-0000-1000-8000-00805f9b34fb</strong></p>
  </blockquote>
  
  <p>The above method returns a BluetoothSocket object, but it fails to connect to the HID device, when bluetoothSocket.connect() is called. It gives <strong>IOException: discovery failed</strong></p>
  
  <p>I have searched about this a lot, but no clue how to fix this.</p>
  
  <p><strong>Is it only possible to connect Rfcomm and not HID devices using this approach in Android?</strong> If
  so, then what alternate approach should I use for this? I am using Samsung Galaxy S3 with 
  Android 4.1 in this application and after pairing (from settings) I could type using
  the Bluetooth keyboard in some inbuilt apps like SMS, Email etc. It
  seems to me that connecting to it should be possible, but I am not
  sure if I am using the right approach. I want to read the keypress serial data in my app.</p>
  
  <p>Here's the code which I am using:</p>
  
  <pre><code>private class ConnectThread extends Thread {
      private final BluetoothSocket mmSocket;
  
      public ConnectThread(BluetoothDevice device) {
          BluetoothSocket tmp = null;
          try {
              tmp = device.createRfcommSocketToServiceRecord(mUUID);
          } catch (IOException e) {
              e.printStackTrace();
          }
          mmSocket = tmp;
      }
  
      public void run() {
          try {
              mmSocket.connect();
          } catch (IOException connectException) {
              try {
                  mmSocket.close();
              } catch (IOException closeException) { }
              return;
          }
  
          Log.d(TAG, "ConnectThread connection successful");
      }
  
      public void cancel() {
          try {
              mmSocket.close();
          } catch (IOException e) { }
      }
  }
  </code></pre>