What is Notification
Android allows to put notification into the titlebar of your application. The user can expand the notification bar and by selecting the notification the user can trigger another activity.
A notification is a message you can display to the user outside of your application's normal UI. When you tell the system to issue a notification, it first appears as an icon in the notification area. To see the details of the notification, the user opens the notification drawer. Both the notification area and the notification drawer are system-controlled areas that the user can view at any time.
Elements of Notification
- Content title
- Large icon
- Content text
- Content info
- Small icon
- Time that the notification was issued.
Creating a Notification
We need to specify the UI information and actions for a notification in a NotificationCompat.Builder object. To create the notification itself, you call NotificationCompat.Builder.build(), which returns a Notification object containing your specifications. To issue the notification, you pass the Notification object to the system by calling NotificationManager.notify().
A Notification object must contain the following:
- A small icon, set by setSmallIcon()
- A title, set by setContentTitle()
- Detail text, set by setContentText()
The following code snippet illustrates a simple notification that specifies an activity to open when the user clicks the notification. Notice that the code creates a TaskStackBuilder object and uses it to create the PendingIntent for the action
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, ResultActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(ResultActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(mId, mBuilder.build());
Removing or Cancelling Notifications
Notifications remain visible until one of the following happens:
The user dismisses the notification either individually or by using "Clear All" (if the notification can be cleared).
The user clicks the notification, and you called setAutoCancel() when you created the notification.
You call cancel() for a specific notification ID. This method also deletes ongoing notifications.
You call cancelAll(), which removes all of the notifications you previously issued.
Nice post with great details. I really like your job. Thanks for sharing. mass notification software
ReplyDeleteHi,
ReplyDeleteI need your help for Notification....My app is dealing with sensex related data. I want to setAlarms for specific sensex value whether my app is running or closed. e.g if I set Alarm in my app for gold rates of 25000, whenever sensex value reach to 25000 i should get alarm or notification whether my app is running or not....It's very urget plz!!!!
Hi,
ReplyDeleteI want your help for sending of Notifications. In my app i have to set notifications from 5 activities, how to set notifications from all activities at user selected time and repeated days like(mon,tue,fri,... and every hour, every two hour, every six hour, etc,..)
thanks you for sharing this tutorial. I am a newbie and i find tutorials on your site very helpful. I am a big fan of learning by doing. Another important trick is to download an apk from apkmonk or apkmirror then decompile it using java compiler. Using this technique one can get code written in production environments.
ReplyDeleteThanks so much for this information. sb game hacker apk I have to let you know I concur on several of the points you make here and others may require some further review, game killer apk but I can see your viewpoint. geometry dash full apk
ReplyDeletethanks. Actually i like notification bar on Android 4.4 more than Android 5.x
ReplyDeleteuseful information for learner like me. Thank you. I also recommend the app game :brain it on for pc . read guideline here
ReplyDeleteThank for your great post.
ReplyDeleteI have been able to create my first Android app after reading, and in addition, I would like to suggest everybody to check out android quiz and interview questions, it may be helpful for one who is preparing for a job interview
Indus Valley Mukteshwar constructed & delivered several deluxe cottages & apartments in Mukteshwar, Nainital. Contact for more information.
ReplyDeletecottages in nainital for sale
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteuktvnow apk : in the event that you need to watch online most adored motion pictures and serials. click on uktvnow and watch online most adored motion pictures and serials.uk tv now apk is an well known app for movies.go and uktvnow download.
ReplyDeleteHai i liked your site and grt most of the important information from here and liked that page i wants to show some apps which are blocked from you tube and you can download from here Show Box APK
ReplyDeleteI really liked and enjoy your site. I have tell you about the Spotify apk. This is a app which is most famouse music app.
ReplyDeleteSpotify for pcs/laptops
Spotify free apk
Wonderful blog, thanks for sharing this type of information. Your website gives the best idea about my interesting information. Any issue related to Online acting classes you can visit the ICE-Balaji website.
ReplyDeleteFirst of all, thank you for your post. Your posts are neatly organized with the information I want, so there are plenty of resources to reference. I bookmark this site and will find your posts frequently in the future. Thanks again ^^์จ๋ผ์ธ์นด์ง๋ ธ
ReplyDelete(mm)