/** Will cancel an in-progress connection, and close the socket */
 public void cancel() {
   try {
     mmSocket.close();
   } catch (IOException closeException) {
     System.out.println("ConnectThread cancel failed. error : " + closeException.toString());
     mmConnectionManager.connectionFailed(closeException.getMessage());
   }
 }
  public void run() {
    try {
      // Connect the device through the socket. This will block
      // until it succeeds or throws an exception
      mmSocket.connect();
    } catch (IOException connectException) {
      System.out.println("ConnectThread run failed. error : " + connectException.toString());
      // Unable to connect; close the socket and get out
      mmConnectionManager.connectionFailed(connectException.getMessage());
      try {
        mmSocket.close();
      } catch (IOException closeException) {
        System.out.println("ConnectThread close failed. error : " + closeException.toString());
        mmConnectionManager.connectionFailed(closeException.getMessage());
      }
      return;
    }

    // Do work to manage the connection (in a separate thread)
    // manageConnectedSocket(mmSocket);
    mmConnectionManager.connectionEstablished(mmSocket);
  }