title: Detect bluetooth device disconnected
body: <p>I'm trying to find out if I can reliably detect when the bluetooth connection with a (non-audio) device has been lost. The Android SDK provides a Bluetooth Chat example, which uses this snippet:</p>
  
  <pre><code>public void run() {
      Log.i(TAG, "BEGIN mConnectedThread");
      byte[] buffer = new byte[1024];
      int bytes;
  
      // Keep listening to the InputStream while connected
      while (true) {
          try {
              // Read from the InputStream
              bytes = mmInStream.read(buffer);
  
              // Send the obtained bytes to the UI Activity
              mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer)
                      .sendToTarget();
          } catch (IOException e) {
              Log.e(TAG, "disconnected", e);
              connectionLost();
              break;
          }
      }
  }
  </code></pre>
  
  <p>How reliable is this method when I start the thread and disconnect the device 12 hours later without using the app (The service runs in background). The service could always be killed ofcourse?</p>
  
  <p>Then there are broadcasts. Will my app always receive these broadcasts? When will it not? I've tried implementing that by using this in the AndroidManifest:</p>
  
  <pre><code>    &lt;receiver android:name="MyReceiver" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.bluetooth.device.action.ACL_CONNECTED" /&gt;
              &lt;action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" /&gt;
              &lt;action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>I've tested both methods in a short time period, and both work. 
  As said before, I'm not sure if these are reliable when the phone is idle for a long time.</p>
  
  <p>Who can shed a light on this?</p>