Using Notification Bar – Android tutorial

In this tutorial we are going to learn how to use the Notification Bar: This is very useful, and is used almost in every application that runs in the background, or that is activates by events. In this example we will add a button that when pressed will open send a notification to the notification bar, with Title and Text, and will also make the Led of the phone blink with a purple color.
  • Add notification Title
  • Add notification Text
  • Add Picture to the notification
  • Make the Trackball Led Blink (For telephone that have the SW only)
  • Chane the color of the blinking Led
In this learn by example, most of the explanation will be inside the code. Lets Start: We will start by adding the Button we are going to use to send a notification to the phone.

<linearlayout xmlns:android=""
   <button android:id="@+id/Button1"
        android:text="Send Notification" />

The next step is to add some code behind the button, so it does what we want in the file we add in the onCreate function the fallowing:
public void onCreate(Bundle savedInstanceState)

        Button1Action Button1Obj    = new Button1Action();
        Button1               = (Button) findViewById(;

    }/* End of onCreate Method */
We now add the class that takes care of the notification. To send a notification we will need to add an intent, with the text we want to add to the notification Inside the UsingNotificationBar class we need to add the fallowing class:
public class Button1Action implements Button.OnClickListener
      public void onClick(View arg0)
         /* Get the notification manager  */
         mNotManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

         /* Create a notification */
         String MyText = "Text inside: By";
         mNotification = new Notification(
                R.drawable.icon,                // An Icon to display
                MyText,                         // the text to display in the ticker
                System.currentTimeMillis()       ); // the time for the notification

         /* Starting an intent */
         String MyNotifyTitle = "Firstdroid Rocks!!!";
         String MyNotifiyText  = "Firstdroid: our forum at";
         Intent MyIntent = new Intent( getApplicationContext(), UsingNotificationBar.class );
         MyIntent.putExtra("extendedTitle", MyNotifyTitle);
         MyIntent.putExtra("extendedText" , MyNotifiyText);
         PendingIntent StartIntent = PendingIntent.getActivity(  getApplicationContext(),

         /* Set notification message */
         mNotification.setLatestEventInfo(   getApplicationContext(),

         mNotification.ledOnMS  = 200;    //Set led blink (Off in ms)
         mNotification.ledOffMS = 200;    //Set led blink (Off in ms)
         mNotification.ledARGB = 0x9400d3;   //Set led color

         /* Sent Notification to notification bar */
         mNotManager.notify(  NotificationId , mNotification );            

      }/* End of method onClick */

    }/* End of Class Button2Action_CDT */
Also, do not forget the imports we need:
package firstdroid.tutorial.UsingNotificationBar;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
That is all, now run the code and you should see the fallowing: Application as it startsGet the notificationreceiving the notification Any Question, Comment or Remark please refer to our forum: forum Enjoy, Firstdroid.