Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login

You must be logged to download. Click here to login


MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation


MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

How to update the Android Status Bar

The Android status bar is one of the most important components in the Android System. In this article we will see how to update the Android Status Bar.

Most of the applications use the android status bar in the bottom position, otherwise they are kept as hidden. Actually this system is supported via two types of processes: one process is that show and hidden criteria of the system and the other process is that only hidden. Actually in the android system, it is necessary for all types of apps for updating the result, so we should update our Android status bar with the information as and when necessary. When we update the android status bar, it gives us a notification. Through the status bar updating protocol, we can easily get updated information about other parts of the apps. In this article we will be discussing the process of updating and using the status bar. Sometime new users of the android system get confused about the updating process, so here we will discuss various types of methods to easily update the apps.

Concept of constructing the status bar:

The best technique to describe the status bar is to show it via Image -I. It is a mobile apps status bar with multiple icons present.

The status bar with multiple icons presen

Figure 1: The status bar with multiple icons present.

Process to view status bar icons:

In Figure 2, the first icon is a calendar notification informing us that we have an appointment with a collaborator today. The second icon is telling us that the device is connected to another device (a computer) via Universal Serial Bus, and the third icon informs us that Universal Serial Bus debugging is enabled. We can press and slide the status bar down and receive more information as shown in figure 2. We can see that each notification has a long-drawn-out view that gives us more information about each icon. The user can select the expanded view to get more details.

Opening the status bar and showing the USB Connected, Notification etc.

Figure 2: Opening the status bar and showing the USB Connected, Notification etc.

Process to use the status-bar tools to notify the user:

The status bar provides various types of tools for notifying the users. Simple icons floating at the top of the screen in the notification area are not our only options in the system. We can develop it with various types of systems and features. We can augment our notification by providing additional flags during the notification process. Some of these options are as mentioned in the table below.






This is the vibration option and we can vibrate the device when the notification occurs. This is useful when the user has the device in this pocket.



This sound option is the application. Sound some type of alarm when the notification occurs, such as a ringtone or prerecorded tone that we install with our application. This is useful if the user has the notification sound level cranked up.



Many devices contain a Light Emitting Diode that we have programmatic access to. We can tell the light to flash at a given interval with a specific color that our program choose. If the Light Emitting Diode only supports one color (such as white), it will flash white, ignoring our color requirement. If the user has the device set to silent, using lights delivers an excellent cue that something needs attention.

Table 1: Showing different notification options

Adding these various options to your notification arsenal can help immensely because they let the user know that something has happened on the device. The status bar is a very powerful tool because it can be used to provide valuable feedback to the user throughout the lifetime of the application. While icons, vibration, lights, and sound might sound like a golden jackpot, that’s not the end of the rainbow. Notifications also allow you to provide scrolling information to the user. This is the information that shows when the notification first arrives. After that, the user needs to slide down the status bar to see the expanded view.

The status bar framework can be used to inform users of various activities such as device state, new mail notifications, and even progress downloads, as shown in figure 3.

The progress loader shows the progressive record or information.

Figure 3: The progress loader shows the progressive record or information.

The Different types of notifications can contain different views. As per developer concept we have programmatic access to provide custom expanded views. The expanded view is the view that is present when the user slides the status bar down.

Using the Notification Manager:

Actually, the notification manager allows interface with Android’s notification mechanism. Notifications appear in the status bar at the top of the device screen. The working with the NotificationManager is as simple as asking the current context for it. If we are within an activity, the code is as follows:

NotificationManager mgr = (NotificationManager) getSystemService (NOTIFICATION_ SERVICE);

This line of code obtains the NotificationManager object from the getSystemService () call.

Process to create your first notification in the Android Status Bar:

The Task Reminder application needs a way to notify the user that a task needs attention. This would happen when the alarm goes off for that particular task. To set this notification in the status bar, we need to use the NotificationManager in the doReminderWork () method of the ReminderService class.

Implementation of doReminderWork ()

This is the simple code implemented in our system. After writing the code we just divided it in sections and provide brief discussion about it.

Listing 1: Showing implementation of notification

Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID);  	//Section 1
NotificationManager mgr =
(NotificationManager)getSystemService(NOTIFICATION_SERVICE); 		//Section 2
Intent notificationIntent = new Intent(this, ReminderEditActivity.class); 		//Section 3
notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID, rowId); 		//Section 4
PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_ONE_SHOT);  							//Section 5
Notification note=new Notification(android.R.drawable.stat_sys_warning,
System.currentTimeMillis());								//Section 6
note.setLatestEventInfo(this, getString(R.string.notifiy_new_task_title),
getString(R.string.notify_new_task_message), pi); 					// Section 7
note.defaults = Notification.DEFAULT_SOUND; 					// Section 8
note.flags = Notification.FLAG_AUTO_CANCEL; 					// Section 9
//an issue could occur if the user ever enters over 2,147,483,647 tasks. (This is maximum  //integer value).
//highly doubt this will ever happen. But is good to note the process
int id = (int)((long)rowId);  								// Section 10
mgr.notify(id, note); 									

Let us discuss the details below.

Section 1: The section is the intent that started the ReminderService. It contains the row Identification of the task that we are currently working with. We basically need this Identification because we will set this as part of the PendingIntent for the status system. When the notification is selected from the status bar, we generally want the ReminderEditActivity to start with the row Identification as part of the pending intent. That way, the ReminderEdit- Activity will open, read the data about that particular row ID, and display it to the user.

Section 2: In Section 2, we are getting an instance of the NotificationManager.

Section 3: In section, we are building a new intent and setting the class to ReminderEdit- Activity. This is the activity that we would like to start when the user is selected the notification process.

Section 4: In this section, we just put the row Identification into the intent.

Section 5: Here we just set up a pending intent to be used by the notification system. Because the notification system runs in another process, and a PendingIntent is required very much in the specific zones. The FLAG_ONE_SHOT flag is used to indicate that this is the pending intent which can only be used once (not more than one time)

Section 6: In this section, the line builds the Notification that shows up in the status bar.

Actually the Notification class accepts the following parameters and their application:






This is the icon parameter, android.R.drawable.stat_sys_warning actually the resource the Identification of the icon to place in the status bar. This icon is a small triangle with an exclamation point in the middle. This is a built-in Android icon, we do not have to worry about providing small-, medium-, or high-density graphics; they are already built into the platform.



This is ticker Text Parameter The tickerText getString(R.string.notify_new_task_message): The text that flows by when the notification first activates.



This parameter is another input to System.currentTimeMillis(): The time to show in the time field of the notification area. Basically the twelve lines set the content of the long-drawn-out view with that standard Latest Event layout as provided by Android. As per illustration, we could provide a custom layout to display. In this instance, we are not providing a custom layout; we are simply providing the stock notification view.

Table2: Showing notification class parameters.

The setLatestEventInfo () method accepts the following parameters:





context: this

The context to associate with the event info system.



getString(R.string.notifiy_new_task_title): The title that goes into the expanded view process.



getString(R.string.notify_new_task_message): The text that goes into the expanded view point



The intent to launch when the expanded view is selected.

Table 3: Parameters for EventInfo () method.

Section 7: In this section, we set the Notification objects to include sound during the notification process. This forces the default notification sound to be played if the user has the notification volume on.

Section 8: In this section, we set the Notification object flags of the property that cancels the notification after it is selected by the user.

Section 9: In this section, we cast the Identification to an integer. The Identification stored in the SQLite database is a long; however, we are casting it to an integer. A loss of precision is happening. However, we highly doubt that this application would ever have more than 2,147,483,647 tasks set up (which is the maximum number that an integer can store in Java). Therefore, this casting should be okay and perfect. The casting to an integer is necessary because the code on line 20(twenty) only accepts an integer (not a decimal point value) as the Identification for the notification.

Section 10: This section raises the notification to the status bar. The notify() call accepts two parameters:

  • One: id: An Identification that is unique within our application process.
  • Two: note: A Notification object that describes how to notify the user in the system.

Concept of the Viewing the workflow process:

The previous code allows the following workflow to occur. Actually through the workflow we can easily get different types of information:

  • The user is active in another application, such as e-mail (electronic mail system).
  • A task is due and therefore the alarm fires. The notification is created in the status bar systems.
  • The user can elect to slide down the status bar and select the notification or ignore it for now. If the user chooses to slide, open the status bar and select an item, the pending intent within the notification will be activated automatically. This in turn causes the ReminderEditActivity to open with the given row Identification of the task process.
  • The notification can be easily removed from the status bar.
  • The task information is retrieved from the database and displayed on the form in the ReminderEditActivity.

How to add string resources in the Android status bar area:

Generally we may observe that we need to add the following two string resources, the resources are:

  • One-notify_new_task_message: We have set the value of this to “A task needs to be reviewed!” This message is used as the message in the expanded view and is used as the ticker text when the notification first arrives in the system or the process.
  • Two-notify_new_task_title: We have set the value of this to “Task Reminder.” This message is used as the title for the expanded view process.

How to update a Notification in the Android status bar area:

At some point in time we might need to update the view of our different types of notifications. Consider the following situation: We have some code that runs in the background to see whether the tasks have been reviewed or not. This code checks to see whether any notifications are overdue or not. We decide that after the two to three hour mark passes, we want to change the icon of the notification to a red-colored exclamation point and flash the Light Emitting Diode [LED] quickly with a red color. Thankfully, updating the notification is a fairly simple process. If we call one of the notify() methods with an Identification process that is currently active in the status bar, and with a new set of notification parameters, the notification is updated in the status bar. Therefore, we would simply create a new Notification object with the red icon as a parameter and call the notify() which would update the notification system.

Process to show the Clearing of a Notification:

This is the point of the view that shows that the users are by far the most unpredictable group because they could be anywhere in the world! They could be first-time users, advanced power users, and so on. At some point in time our user sees a notification and decides to open the app (the manual/long way) via the app launcher protocol. If the user decides to open our application system via the app launcher then also our notification will persist. Even if the user looks at the task at hand, the notification will still persist on the status bar.

While this is not a big deal, actually our application should be able to recognize the state of the application and should take the appropriate measures to cancel any existing notifications that might be present for the given task. However, if the user opens our app and try to review a different task that does not have an active notification, we should have not cleared any previous notifications.

Only clear the notification which the user is reviewing in the process. The NotificationManager makes it real simple to cancel an existing notification with the cancel() method process. The cancel() method accepts only one parameter and the Identification of the notification. Remember how we used the Identification of the task as the Identification for the note? The Identification of the task is primary key to the Task Reminder application. By doing this, we can easily open a task and cancel any existing notification by calling the cancel() method with the Identification of the task. At some point of time, we might also need to clear all the previously notifications. To do this job, simply call the cancelAll() method on the NotificationManager and process it.

Procedure to display the Status bar Notifications in Android:

Actually the Developers of the Android system are no doubt familiar with the Toast class, it displays a little pop-up having whatever message we want to display to the user. This Toast pop-up will automatically dismiss itself after a while. Actually it is made useful as a tool to provide timely feedback to the user (such as informing the user that a file has been saved successfully), but not a really good tool to use for some asynchronous action (such as telling the user that an incoming Short message Service (SMS) message has arrived). For the latter, we can make the use of the Status Bar Notification feature of the Android system, which displays a persistent notification on the status bar of our Android device. This notification can be dismissed when the user has read it properly or carefully, and thus this makes it a good tool for delivering notifications to the users to respond at their convenient way. In this article, we shall walk the user through the steps to create status bar notifications for our Android application.

Actually the concept of the Status Bar is that it is transparent with a subtle shadow to back the all-white-all-the-time icons. This is a leap from the solid black bar with #33B5E5 [Hexadecimal Code] icons from Android 4.3 version (which turn gray when not fully connected or active at the time of processing the system). Additionally, the network activity arrows only appear in the quick settings panel. The Overall, network connectivity has been made strangely more opaque in KitKat [An upgraded version of the Android Operating System]; though for many average users this is not a huge concern.

Basically the pull-down behavior is obviously still present to access our notifications, and the notification shade itself is largely untouched except for white iconography and highlights.

Process to get the Height of the Status Bar in Android device:

Sometimes it happens that in Android, the flexible layout system is not flexible enough and we need to make some computations inside our code. In these computations, we may need to subtract the size of the status bar. In this article we will give some answers, but they all rely on the fact that the status bar is shown at the time when the user makes the computation process.


Normally the above code does not work properly, for that reason we are going to another process for accessing the record and information from the system.

The height of the status bar is contained in a dimension of the resource which is called status_bar_height. It is not a part of the public resources process, so we cannot access it directly from our code with android.R.dimen.status_bar_height. We can however compute it at runtime with the following code:

Listing 2: Showing to get the status bar height

public int getStatusBarHeight_android() // this is function for android status bar height.
  	int result = 0;
	 int resourceId = getResources().getIdentifier("status_bar_height", "SGC", "android");
  if (resourceIdentification > 0)
      result = getResources().getDimensionPixelSize(resourceIdentification);
  	return result; //as it is return type function so here return the result.

Generally we need to put this method in a ContextWrapper class

This image shows the height of the status bar.

Figure 4: This image shows the height of the status bar.

Note: This is an interesting tip to get the height size of status bar and title bar, assuming that they are both on the top of the screen.

Listing 3: Sample showing status bar display

public void onCreate_process(Bundle saved_Instance_State) // create function 
    super.onCreate(saved_Instance_State); // call super to send data at base class constructor
    setContentView(R.layout.main); // This method use for set content view 
     tvContent = (TextView)findViewById(;
    tvContent.postDelayed(new Runnable() 
        public void run() 
             String display_satus = String.format("Status Bar Height is = %d\nTitle Bar Height is = %d", getStatusBarHeight(), getTitleBarHeight());
    }, 2000); //Give the size as per the pixel parameter
public int getStatusBarHeight_android()  //return value method for the accessing data or information 
    Rect rect1 = new Rect(); //Initialize the object rect1 
    Window w = getWindow();
    w.getDecorView().getWindowVisibleDisplayFrame(rect1); //Frame will be create and pass the object
    return; //here return the variable
public int getTitleBarHeight_android()  
    int viewTop = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
    return (viewTop - getStatusBarHeight()); //Here we subtract data from viewTop to getStatusBarHeight 

Different types of icon that says different types of Information at Status bar:

The progress loader in the status bar. Shows the progressive record or information

Figure 5: The progress loader in the status bar. Shows the progressive record or information

The above picture generally shows all types of icons that have different types of process control features and these features are generally shown at the status bar. Here we are trying to provide all types of necessary icons and their uses so that users can easily understand what types of messages are displayed on the status bar.

Nowadays, lots of apps are present in the Google play or in other systems. These apps are updated and upgraded based on the up-gradation of the android operating systems. The latest concept is Android1, and few companies have priority to develop the systems like Micromax, Lava, and Spice. Also the new Android version is Lollipop. These companies are developing with protocols of Google system. In these circumstances, we are developing the android status bar. At first we have said that the status bar can be represented as a hidden process, shown process, or shown and hidden process. Then we have discussed the processes in details. We have also covered different parameters and their implication on the application development. The status bar is one of the most important components as it can be used for various purposes. To manage the functionalities of the status bar there are various controls available. The developers must be aware of the components as well as their usages. Hope this article has covered these issues and given a clear direction to the developer community.

Website: Have 16 years of experience as a technical architect and software consultant in enterprise application and product development. Have interest in new technology and innovation area along with technical...

What did you think of this post?
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!

> More info about MrBool Credits
You must be logged to download.

Click here to login