Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Windows Mobile – Remove the Backup Battery Very Low Notification Balloon

0.00/5 (No votes)
30 Aug 2005 1  
How to remove the annoying “Backup Battery Very Low” (bogus) critical notification programmatically.

Introduction

The following code snippet demonstrates a way to programmatically remove "backup battery very low" system notification message-balloon from the system and its icon from the navigation bar of the Windows Mobile device screen. Why this is useful and what problem it solves is being discussed in the next section – “Background”.

Background

Whenever the backup-battery of a device becomes very low, the Windows Mobile based Pocket PC devices would pop up a critical system notification balloon with an icon in the navigation bar to notify the user that the system backup battery is running critically low. This is indeed a critical device condition, and the user is expected to take swift action to replace/recharge the backup battery accordingly to avoid potential data loss.

However, some of the devices that are in the current market either do not have a way to get to where the backup battery is located so that it can be replaced, or for some, even if the battery is replaced, the message-balloon pops up every so often when they cycle the device power, for example. In the latter case, it is a bogus condition, which is annoying to many.

Although, this notification goes away once the user acknowledges the pop up notification, the situation is quite different for applications that are running as Kiosks (full screen mode). In this case, the notification message-balloon never pops up, but the icon is being displayed in the navigation bar, and there is no way to get rid of it.

I found a simple workaround for the above-mentioned situation. You may use the workaround as it fits.

Using the code

The logic behind the workaround is quite simple. There are a couple of tricks involved, though. The logic is to enumerate through the system notifications and find the handle to the "backup-battery very low" notification, and if one is found, remove the notification from the system programmatically.

First of all, be cautious to have a mechanism in place to distinguish the difference between the bogus situation that this notification pops up and the actual condition that the user should take appropriate action to prevent potential data loss.

Second of all, you may need a way to obtain the CLSID for the notification’s COM interface from its text form. You may use CLSIDFromString() function as shown in the code snippet. This function has been implemented in ole32.lib and oleaut32.lib libraries. You may want to #include objbase.h header in your project as well.

Furthermore, the SHNotificationGetData() function call requires a unique notification ID to be passed into the function, which we do not possess. Different platform vendors have assigned different IDs to this same notification making it harder to guess. So, in my workaround, I try different IDs starting from 0 and incrementing by 1 sequentially upon each failed call. In all the platforms that I have tried, there could be a matching ID found within less than 2000 attempts. You may want to experiment for the platforms that you develop first, just to get an idea. It would be nice if your platform vendor can provide you this ID value. If not, you can still use the method that I use.

I have successfully utilized this method in eVC++ 3.0 and 4.0 projects with Windows Mobile 2002/2003/2003SE devices from several vendors.

//*********************************************************************************
//* Method Name: RemoveLowBattMessage()
//*
//* Description: Remove the "Backup Battery Very Low" Notification.
//*
//* Argument(s): none
//* Return type: void
//********************************************************************************
void RemoveLowBattMessage()
{
     SHNOTIFICATIONDATA shnd;
     CLSID clsid;
     LRESULT result;
     DWORD dwID = 0;
 
     if (0 == CLSIDFromString(TEXT("{A877D663-239C-47a7-9304-0D347F580408}"), 
                                                                   &clsid)) {
         memset(&shnd, 0, sizeof(shnd));
         shnd.cbStruct = sizeof(SHNOTIFICATIONDATA);
         do {
              result = SHNotificationGetData(&clsid,dwID,&shnd);
              if (ERROR_SUCCESS == result) {
                   SHNotificationRemove(&clsid,dwID);
                   if (shnd.pszHTML) free((void *) shnd.pszHTML);
                   shnd.pszHTML = NULL;
                   if (shnd.pszTitle) free((void *) shnd.pszTitle);
                   shnd.pszTitle = NULL;
              } else dwID++;
         } while ((ERROR_SUCCESS != result) && (dwID < 2000));
     };
}

Points of Interest

It was great fun for me to think this through. This bogus message has given us a huge annoyance for quite a long time until I came up with this idea to get it removed programmatically. There is nothing magical in this logic. Also, this same approach can be used to remove any of the system notifications that you might not want. Be careful, though!

History

  • August 30th, 2005 – Initial posting to The Code Project.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here