tags:

views:

40

answers:

1

With my notification system, when the notification is sent, I would like to be able to click on the notification and have it send me to my application. But, with my current code, it doesn't do so. How can I fix that?

public void causeNotification(CharSequence contentText, CharSequence tickerText) {
    Log.d(TAG, "Sending notification - \"" + contentText + "\"");
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    int icon = R.drawable.neoseeker_swoosh;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    notification.defaults |= Notification.DEFAULT_ALL;
    notification.defaults |= Notification.FLAG_AUTO_CANCEL;

    Context context = getApplicationContext();
    CharSequence contentTitle = "Neoseeker";
    Intent notificationIntent = new Intent();
    PendingIntent contentIntent = PendingIntent.getActivity(Neoseeker.this, 0, notificationIntent, 0);

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

    mNotificationManager.notify(Neoseeker.NOTIFICATION_ID, notification);
}
A: 

Step #1: Never call getApplicationContext(). Neoseeker.this apparently is a Context -- use it.

Step #2: notificationIntent is an empty Intent. That is not going to open any activities. You need to create an Intent that would start an activity, much like any Intent you would use with startActivity().

Here is a sample project from one of my books, showing the use of notifications.

CommonsWare
Worked like it should, thanks mate!
Chiggins