title: Android Bluetooth Broadcast Receiver Issues with ACL_CONNECTED and AC_DISCONNECTED
body: <p>I am writing an app that detects whether or not a bluetooth device is connected. After doing some research I found that the best way to do it was to use a broadcast receiver with some bluetooth related intent filters.</p>
  
  <pre><code>&lt;receiver android:name=".BTReceiver" &gt;
              &lt;intent-filter&gt;
              &lt;action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED" /&gt;
              &lt;action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED" /&gt;
              &lt;action android:name="android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED" /&gt;
              &lt;action android:name="android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" /&gt;             
              &lt;/intent-filter&gt;  
          &lt;/receiver&gt;
  </code></pre>
  
  <p>And here is my bluetooth receiver class.</p>
  
  <pre><code>@Override
      public void onReceive(Context context, Intent intent) {     
          String action = intent.getAction();
          if(action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED") || action.equals("android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED") ){
              Log.d("Z","Received: Bluetooth Connected");
          }
          if(action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED") ||action.equals("android.bluetooth.BluetoothDevice.ACTION_ACL_DISCONNECTED_REQUESTED")){
              Log.d("Z","Received: Bluetooth Disconnected");
          }
          Log.d("Z",action);
  }
  </code></pre>
  
  <p>When I turn on my bluetooth headset and it connects to my phone, I receive "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED" twice. When I disconnect the bluetooth headset, the broadcast receiver doesn't run or receive anything. So I never receive my Bluetooth Disconnected Log message. I am using the two bluetooth permissions that I thought were necessary to get this to work.</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
      &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
  </code></pre>
  
  <p>I could really use any information on what is wrong here. Thank you.</p>