Notifications Made Easy

by Administrator on ‎06-09-2010 12:52 PM - edited on ‎06-09-2010 01:12 PM by BlackBerry Development Advisor (Retired) (9,103 Views)

Overview


Many applications require the ability to alert a BlackBerry® smartphone user that an event occurred.  This could be achieved by playing an audio alert, vibrating or flashing the LED.  Many developers attempt to manually trigger these alerts from within their application but with only a few lines of code an application is able to integrate with and appear within the Notification/Profiles application of a BlackBerry Smartphone.  This type of implementation provides a number of benefits to the developer and the end user:

 

  • The User can configure the alert for all applications in a central location using consistent options.
  • Default alerts are pre-configured for each profile type (For example, Set to Vibrate only for the Vibrate profile, volume level set to maximum for the Loud profile and notifications disabled for the silent profile).

 

It also benefits the developer in that the application does not need to implement the code to provide a GUI for the user to choose their type of alert, store their alert options or to trigger the chosen alert.

 

Implementation

 

The first step in using this type of notification is to register your application with the Notification/Profiles application. 

 

 

// Long value com.samples.simpleNotification
private static final long ID = 0x749cb23a75c60e2dL;


//The toString value of this object will be displayed in the user's Profile settings.
Object theSource = new Object()
{
public String toString()
{
return "Simple Notification";
}
};

//Register the notification.
NotificationsManager.registerSource(ID, theSource, NotificationsConstants.IMPORTANT);

 

Once registered, an application is able to trigger the alert the user has configured.

 

 

NotificationsManager.triggerImmediateEvent(ID, 0, null, null);

 

A complete sample application is attached.