Wednesday, 23 May 2012

Simple Notification Example

Put Below Code in onClicklistener( ) event of Button

Timer timer = new Timer();
timer.schedule(new TimerTask() {
    @Override
public void run() {
// Notification Title and Message
Notification("This is message from Dipak Keshariya (Android Application Developer)", "This is Android Notification Message");
}
}, 0);


And write below Method in your MainActivity

private void Notification(String notificationTitle, String notificationMessage) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    android.app.Notification notification = new android.app.Notification(R.drawable.ic_launcher, "A New Message from Dipak Keshariya (Android Developer)!",
  System.currentTimeMillis());

Intent notificationIntent = new Intent(this, AndroidNotifications.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(AndroidNotifications.this, notificationTitle, notificationMessage, pendingIntent);
  notificationManager.notify(10001, notification);
}

And Now Run Your Project.

Enjoy :-)

Don’t forget to provide feedback or follow this blog, if you find this blog is useful.

8 comments:

  1. can you explain this in detail...

    ReplyDelete
  2. how to open the notification message in activity with that message?

    ReplyDelete
  3. Simple and useful. Beautiful. :)

    ReplyDelete
  4. Very Nice Tutorial....

    ReplyDelete
  5. could you please tell me how to store the entered emailid in text field in sqlite database

    ReplyDelete
  6. Want to show notification after every 48hours how can I do it?
    please help me question posted here on stack overflow
    contentIntent

    ReplyDelete