1. a notification manager manage everything.
2. a notification itself has the icon, sounds, and ticker.
3. a Intent that is going to run when an user click the notification.
notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE); notification = new Notification(); notification.icon = R.drawable.icon; notification.defaults = Notification.DEFAULT_SOUND; notification.tickerText = "Bu......."; notification.flags |= Notification.FLAG_AUTO_CANCEL; Intent notifyIntent = new Intent(getBaseContext(), ServiceDemo.class); PendingIntent PendTntent = PendingIntent.getActivity(this, 0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); notification.setLatestEventInfo(this,"Title","Check the latest update",PendTntent);
Once you have everything ready, you can use the following code to trigger the notification.
notificationManager.notify(0, notification);
No comments:
Post a Comment