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.
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.
Nice tutorial.
ReplyDeletecan you explain this in detail...
ReplyDeletehow to open the notification message in activity with that message?
ReplyDeleteExcellent!
ReplyDeleteSimple and useful. Beautiful. :)
ReplyDeleteVery Nice Tutorial....
ReplyDeletecould you please tell me how to store the entered emailid in text field in sqlite database
ReplyDeleteWant to show notification after every 48hours how can I do it?
ReplyDeleteplease help me question posted here on stack overflow
contentIntent
Beautiful example. A simple code for a simple notification. Salam FROM Indonesia.
ReplyDeleteOur Pay for affordable term papers, customer access our term paper writing services knowing that they are assured of the best quality essay lest they get their money back.
ReplyDeleteI am getting an error on the line of setLatestEventInfo
ReplyDelete