title: Connection refused on bluetooth socket.connect() - android
body: <p>First, I know this issue has been up before but none of the sugested solutions i found solves my problem...</p>
  
  <p>After pairing device with </p>
  
  <pre><code>Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
  tmp = (BluetoothSocket) m.invoke(device, 1);
  </code></pre>
  
  <p>I try to connect using</p>
  
  <pre><code>boolean connected = false;
  String cause = "";
  for(int i=0; i&lt;3; i++){
      try {
          mmSocket.connect(); 
      } catch (IOException e) {
          Log.e("btact","fail"+i+" - "+e.getMessage());
          cause = e.getMessage();
          continue;
      }
      connected = true;
  }
  
  if(!connected){
      try {
          mmSocket.close();
      } catch (IOException e2) {
          Log.e(TAG, "unable to close() " + mSocketType +
                  " socket during connection failure", e2);
      }
  
      Log.e("----btact----", cause);
      connectionFailed();
      return;             
  }
  </code></pre>
  
  <p>This gives me
  fail0 -  Connection refused
  fail1 -  File descriptor in bad state
  fail2 -  File descriptor in bad state
  File descriptor in bad state</p>
  
  <p>Whay may cause this problem and how do I solve it?</p>