title: Click on android notification icon does not trigger broadcast receiver
body: <p>I have an app hooked with push notifications. When the user click on the notification, I want a broadcast receiver to be triggered instead of an activity.</p>
  
  <p>I looked at these threads and looks like this is perfectly possible and common.</p>
  
  <p><a href="https://stackoverflow.com/questions/14841740/android-notification-action-is-not-fired-pendingintent">Android Notification Action is not fired (PendingIntent)</a></p>
  
  <p><a href="https://stackoverflow.com/questions/31937438/send-broadcast-on-notification-click">Send broadcast on notification click</a></p>
  
  <p>However I can't get it to work. I see the notification, but when I click on it and it never triggers my Broadcast receiver.</p>
  
  <p>Here what I have tried:</p>
  
  <ol>
  <li><p>I created a custom receiver:</p>
  
  <pre><code>public class NotificationOnClickReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(final Context context, Intent intent) {
          Log.d(Constants.Engine.LOGGER_TAG_GCM,
                  NotificationOnClickReceiver.class.toString() + " triggered");
      }
  }
  </code></pre></li>
  <li><p>I registered this receiver dynamically on my global Application (not activity)</p>
  
  <pre><code>mNotificationOnClickReceiver = new NotificationOnClickReceiver();
  IntentFilter intentFilterOnClick = new IntentFilter(Constants.Engine.BROADCAST_RECEIVER_FILTER_NOTIFICATION_ONCLICK);
  getApplicationContext().registerReceiver(mNotificationOnClickReceiver, intentFilterOnClick);
  Log.e(Constants.Engine.LOGGER_TAG_DBG, "mNotificationOnClickReceiver = " + mNotificationOnClickReceiver.toString());
  </code></pre></li>
  </ol>
  
  <p>The filter is just a string constant (I wonder if this is the problem)</p>
  
  <pre><code>    public static final String BROADCAST_RECEIVER_FILTER_NOTIFICATION_ONCLICK = "push_notification.onclick";
  </code></pre>
  
  <ol start="3">
  <li><p>Receiver intent setup:</p>
  
  <pre><code>// When the user taps on the notification bar, this is the receiver that I want to be called
  Intent pushNotificationIntent;
  Log.e(Constants.Engine.LOGGER_TAG_DBG, "Notification called!");
  pushNotificationIntent = new Intent(this, NotificationOnClickReceiver.class);
  // Not sure if this causing the problem
  pushNotificationIntent.setAction(Constants.Engine.BROADCAST_RECEIVER_FILTER_NOTIFICATION_ONCLICK);
  // ensures that each notification and intent are unique
  int uniqueCode = new Random().nextInt(Integer.MAX_VALUE);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(
          context,
          uniqueCode,
          pushNotificationIntent, // Receiver Intent
          PendingIntent.FLAG_CANCEL_CURRENT);
  Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
  NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
          .setSmallIcon(mIconId)
          .setContentTitle(context.getString(R.string.myString))
          .setContentText("My GCM Alert!")
          .setAutoCancel(true)
          .setSound(defaultSoundUri)
          .setContentIntent(pendingIntent);
  </code></pre></li>
  <li><p>From the logs, things seem to work except that my Broadcast receiver never gets called:</p>
  
  <pre><code>02-22 15:47:47.092 16863-16863/com.myapp.test E/MYAPP_DBG: mNotificationOnClickReceiver = mytest.broadcastreceivers.NotificationOnClickReceiver@d78f559
  02-22 15:47:53.312 16863-17038/com.myapp.test E/MYAPP_DBG: Notification called!
  </code></pre></li>
  </ol>
  
  <p>If anyone has this working, can you point me out a sample code? I don't see where my bug is.</p>
  
  <p>thank you!</p>