Posted By Our Mentors
Amreen Khan
Android Developer
animesh bansal
iphone App Developer
Devendra chouksey
Android Developer
Dilip Saket
IOS apps developer
Hemraj Jhariya
iOS Developer
Jaihind singh Rajput
Smart Phone App Dev
Mujahid khan
Android developer
Narendra Yadav
android developer
Narinder Gupta
Mobile App Architect
Pradeep singh Thakur
Mobile App Architect
Sanjay Sharma
Andriod Developer
Shakti Rajpal
IT Architect
Soniya Vishwakarma
iPhone App Developer
Sunil Raghuwanshi
iPhone App Developer
Supriya Kapse
Senior developer
View current Topics
Notification in Android (Part-I) Android
What are Notifications? The name itself implies their functionality. They are a way of alerting a user about an event that he needs to be informed about or even take some action on getting that information.
Posted By: Amreen Khan Date: 18 Jul 2012 View: 1426
      Rate This !!

Notification on Android can be done in any of the following ways:
  • ·         Status Bar Notification
  • ·         Vibrate
  • ·         Flash lights
  • ·         Play a sound
I am using the first way to explain its functionality:-

To create a status bar notification, you will need to use two classes: Notification and NotificationManager.
  • ·         Notification defines the properties of the status bar notification like the icon to display, the test to display when the notification first appears on the status bar and the time to display.
  • ·         NotificationManager is an android system service that executes and manages all notifications. Hence you cannot create an instance of the NotificationManager but you can retrieve a reference to it by calling the getSystemService() method.
Once you procure this handle, you invoke the notify() method on it by passing the notification object created.


obtain a handle to the NotificationManager:

     mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

2. Create a notification object along with properties to display on the status bar

final Notification notifyDetails = new Notification(,"New Alert, Click Me!",System.currentTimeMillis());
3. Add the details that need to get displayed when the user clicks on the notification. In this case, I have created an intent to invoke the browser to show the website

Context context = getApplicationContext();
                CharSequence contentTitle = "Notification Details...";
                CharSequence contentText = "Browse allappsdevelopers Site by clicking me";
                Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(""));
                PendingIntent intent =
                    PendingIntent.getActivity(SimpleNotification.this, 0,
                    notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
                notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
                mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

4. Now the stage is set. Notify.
      mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);



All of the above actions(except getting a handle to the NotificationManager) are done on the click of a button “Start Notification”. So all the details go into the setOnClickListener() method of the button.
Similarly, the notification, for the example sake is stopped by clicking a cancel notification button. And the code there is :

Posted Queries