Notification in Android

Public on March 28, 2009
Notification in android is handy way to notify your user. Here is a very simple example of it. We would combine it with WebView with ZoomControls in Android.

First of all rename the Main class on the WebView tutorial to WebActivity making it
public class WebActivity extends Activity {
private WebView myWebView;

Then import the following to your manifest file
<application android:icon="@drawable/icon" android:label="@string/app_name">
  <activity android:name=".WebActivity"/>
<uses-permission android:name="android.permission.INTERNET">

public class Main extends Activity implements View.OnClickListener {
  private Button Button01;
  private NotificationManager mManager;
  private static final int APP_ID = 0;

  public void onCreate(Bundle savedInstanceState) {

    this.Button01 = (Button) this.findViewById(;

    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

  public void onClick(View v) {
    Intent intent = new Intent(this,WebActivity.class);

    Notification notification = new Notification(R.drawable.icon,
"Notify", System.currentTimeMillis());
"App Name","Description of the notification",
PendingIntent.getActivity(this.getBaseContext(), 0, intent,
    mManager.notify(APP_ID, notification);

Quick Explanation:
(Most of it is explained on the android dev site)

mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Call the notification service

Notification notification = new Notification(R.drawable.icon,"Notify", System.currentTimeMillis());
*** Create a new notification with an icon and label and do the notification now. See Notification Class

notification.setLatestEventInfo(Main.this,"App Name","Description of the notification",PendingIntent.getActivity(this.getBaseContext(), 0, intent,PendingIntent.FLAG_CANCEL_CURRENT));
*** Set the info of the notification, see Notification Class

mManager.notify(APP_ID, notification);
Notify the notification manager about our new notification and pass an id for it


PhotoStream Source

Update History
   Jan 17, 2012 - Visual Update

[Advertising]Faster Thinking - Speed up your brain

Faster Thinking Game

sentiment_satisfied Emoticon