I have a NotificationManager that successfully creates a Notification:
private void showNotification() {
Notification notification = new Notification(R.drawable.snog_icon, getString(R.string.sn_g_entering_beacon_mode_),
System.currentTimeMillis());
// The PendingIntent to launch our activity if the user selects this notification
Intent i = new Intent(this, SnogActivity.class);
i.putExtra("fromNotification", "yes");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
notification.setLatestEventInfo(this, getString(R.string.sn_g_avalanche_buddy),
getString(R.string.beacon_mode_activated_), contentIntent);
notification.flags |= Notification.FLAG_ONGOING_EVENT; // Notification.DEFAULT_ALL
// Send the notification.
// We use a string id because it is a unique number. We use it later to cancel.
mNM.notify(R.string.service_started, notification);
}
That part works fine and it shows my notification, and the correct activity is started when I tap the notification. Later in the app I try to notify a simple notification:
Notification not = new Notification(R.drawable.snog_icon, "checker", System.currentTimeMillis());
not.flags |= Notification.DEFAULT_ALL;
mNM.notify(R.string.checker, not);
And that crashes the app in the notify() call with a IllegalArgumentException. I am supposed to use NotificationCompat.Builder according to quite some internet results, but that is not even available.
You could fix this exception, but I would rather do it right from the beginning by using the NotifcationCompat. It is available on the compatibility package, you have to add by Right click on your eclipse project > Android Tools > Add Support Library
after this, you will have the NotificationCompat available in your project…then visit the site: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
there are some great and simple examples there.
Good luck!