Search code examples
androidandroid-pendingintentnotification-bar

Android notification bar click not working


I have following code to make notification in notification bar in C2DMReceiver.java. This class itself extends BroadcastReceiver. and following code is in onReceive method.

    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.ic_call;
    CharSequence text = "Match Found";
    CharSequence contentTitle = "Match";
    CharSequence contentText = received.getExtras().getString("matches");
    long when = System.currentTimeMillis();

    Intent intent = new Intent(context, C2DMReceiver.class);


    PendingIntent contentIntent =  PendingIntent.getBroadcast(context, 0, intent, 0);

    Notification notification = new Notification(icon,text,when);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    notificationManager.notify(34, notification);

Now when I am clicking on notification in notification bar. onReceive method of c2DmReceiver class is not invoking.

Please help...


Solution

  • Did you registered C2DMReceiver in your Manifest file? If you have registered, try changing the below line to the corresponding IntentFilter in Manifest file and check.

    Intent intent = new Intent(context, C2DMReceiver.class);