2

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...

Rahul
  • 1,403
  • 4
  • 18
  • 31
  • You cannot click on the small notification icon in the notification bar and expect something to happen. You can press on the notification in the list of Notifications. – Zelimir Apr 18 '11 at 12:58
  • Yes, I am click on expanded notification only. – Rahul Apr 18 '11 at 13:09
  • Not sure if this will work generally. setLatestEventInfo() should have as the first argument activity/application context, and you use receiver context. – Zelimir Apr 18 '11 at 13:24

1 Answers1

2

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);
MByD
  • 135,866
  • 28
  • 264
  • 277
Sukumar
  • 1,303
  • 10
  • 15
  • Thanks..that was the issue. Added new intent filter to c2dmreceiver in manifest and created pendingintent with action name rather than context – Rahul Apr 18 '11 at 16:00