title: Android Broadcast Receiver bluetooth events catching
body: <p>I'm trying to catch bluetooth state changes with Broadcast Receiver.</p>
  
  <p>My manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
  &lt;application&gt;
       &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  
      &lt;receiver android:name=".BluetoothBroadcastReceiver"
                android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.bluetooth.adapter.action.STATE_CHANGED" /&gt;
              &lt;action android:name="android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED" /&gt;
              &lt;action android:name="android.bluetooth.device.action.ACL_CONNECTED" /&gt;
              &lt;action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>Receiver <code>onReceive</code> method:</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
  
      String action = intent.getAction();
      Log.d("BroadcastActions", "Action "+action+"received");
      int state;
      BluetoothDevice bluetoothDevice;
  
      switch(action)
      {
          case BluetoothAdapter.ACTION_STATE_CHANGED:
              state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
              if (state == BluetoothAdapter.STATE_OFF)
              {
                  Toast.makeText(context, "Bluetooth is off", Toast.LENGTH_SHORT).show();
                  Log.d("BroadcastActions", "Bluetooth is off");
              }
              else if (state == BluetoothAdapter.STATE_TURNING_OFF)
              {
                  Toast.makeText(context, "Bluetooth is turning off", Toast.LENGTH_SHORT).show();
                  Log.d("BroadcastActions", "Bluetooth is turning off");
              }
              else if(state == BluetoothAdapter.STATE_ON)
              {
                  Log.d("BroadcastActions", "Bluetooth is on");
              }
              break;
  
          case BluetoothDevice.ACTION_ACL_CONNECTED:
              bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
              Toast.makeText(context, "Connected to "+bluetoothDevice.getName(),
                      Toast.LENGTH_SHORT).show();
              Log.d("BroadcastActions", "Connected to "+bluetoothDevice.getName());
              break;
  
          case BluetoothDevice.ACTION_ACL_DISCONNECTED:
              bluetoothDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
              Toast.makeText(context, "Disconnected from "+bluetoothDevice.getName(),
                      Toast.LENGTH_SHORT).show();
              break;
      }
  }
  </code></pre>
  
  <p>I launch app then minimize it by pressing Home button. Go to settings and turn on bluetooth but nothing happens. Though I expect toast and logcat messages. What's wrong here?  </p>