public class

NotificationManager

extends Object
java.lang.Object
   ↳ com.neomades.notification.NotificationManager

Class Overview

Local Notification manager.

The local notification manager must be used to show, schedule or cancel local Notification.

Show a notification

NB. In this section we will not talk about the graphical aspect of the notification, this can be done vie the Notification class.

There are several way to display a notification:

When a notification is triggered while the application is in background, it will be displayed to the user. The UI of notification depends of its type. If the application is in foreground when the notification is triggered, nothing visual to the end user will be displayed. However, work can be done on the received notification by overloading onLocalNotificationReceived(Notification). This will enable to display a dialog with the notification data for example.

Requirements

To use local notifications, the LOCAL_NOTIFICATION permission should be declared in the URS project file.

 <urs>
 
 	<permissions>
 		<permission name="LOCAL_NOTIFICATION"/>
 	<permissions/>
 
 <urs/>
 

See Also

Summary

Constants
int INTERVAL_DAY Scheduled notification interval: notify every day.
int INTERVAL_HALF_DAY Scheduled notification interval: notify every 12 hours.
int INTERVAL_HALF_HOUR Scheduled notification interval: notify every 30 minutes.
int INTERVAL_HOUR Scheduled notification interval: notify every 60 minutes.
int INTERVAL_MINUTE Scheduled notification interval: notify every minute.
int INTERVAL_MONTH Scheduled notification interval: notify every month.
int INTERVAL_WEEK Scheduled notification interval: notify every week.
int INTERVAL_YEAR Scheduled notification interval: notify every year.
Public Methods
void cancel(Notification notification)
Cancels a pending notification.
void cancelAll()
Cancels all pending notifications.
Notification findNotificationByExtra(String extra)
Finds a scheduled locale notification by extra value.
Notification findNotificationById(int id)
Finds a scheduled locale notification by identifier.
static NotificationManager getDefault()
Gets the default notification manager.
Vector<Notification> getScheduledNotifications()
Returns the list of all the registered scheduled notifications.
void notify(Notification notification)
Notifies immediately the end-user with a Notification.
void schedule(Notification notification, Calendar date)
Schedules a Notification at one date.
void schedule(Notification notification, int interval)
Schedules a Notification periodically.
void showNotification(Notification notification)
Shows the Notification in the status bar no matter if the application is in background or in foreground.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int INTERVAL_DAY

Scheduled notification interval: notify every day.

Constant Value: 1440 (0x000005a0)

public static final int INTERVAL_HALF_DAY

Scheduled notification interval: notify every 12 hours.

Constant Value: 720 (0x000002d0)

public static final int INTERVAL_HALF_HOUR

Scheduled notification interval: notify every 30 minutes.

Constant Value: 30 (0x0000001e)

public static final int INTERVAL_HOUR

Scheduled notification interval: notify every 60 minutes.

Constant Value: 60 (0x0000003c)

public static final int INTERVAL_MINUTE

Scheduled notification interval: notify every minute.

Constant Value: 1 (0x00000001)

public static final int INTERVAL_MONTH

Scheduled notification interval: notify every month.

Constant Value: 43800 (0x0000ab18)

public static final int INTERVAL_WEEK

Scheduled notification interval: notify every week.

Constant Value: 10080 (0x00002760)

public static final int INTERVAL_YEAR

Scheduled notification interval: notify every year.

Constant Value: 525600 (0x00080520)

Public Methods

public void cancel (Notification notification)

Cancels a pending notification.

Parameters
notification the notification to cancel.
Throws
NullPointerException if the parameter is null

public void cancelAll ()

Cancels all pending notifications.

public Notification findNotificationByExtra (String extra)

Finds a scheduled locale notification by extra value.

Parameters
extra extra value contained by notification
Returns
  • the found notification or null

public Notification findNotificationById (int id)

Finds a scheduled locale notification by identifier.

Parameters
id the notification identifier
Returns
  • the found notification or null

public static NotificationManager getDefault ()

Gets the default notification manager.

Returns
  • the notification manager

public Vector<Notification> getScheduledNotifications ()

Returns the list of all the registered scheduled notifications. Notifications that must be scheduled only once at a specific date will be returned too. Cancelled notifications will not appear in this list.

Returns
  • list of scheduled notifications or empty list if no notification was found or if the current platform does not support notifications.

public void notify (Notification notification)

Notifies immediately the end-user with a Notification.
If the application is in foreground the method: onLocalNotificationReceived is directly called while if the application is in background the Notification is shown in the status bar.

Parameters
notification the notification to show
Throws
NullPointerException if the notification is null

public void schedule (Notification notification, Calendar date)

Schedules a Notification at one date.

Warning: If the application is in foreground state (visible to the end-user), then the notification will not be displayed at the status bar, only the callback method onLocalNotificationReceived will be called.

NB. the trigger of the notification is not very accurate and can vary from some seconds to around one hour on some platforms.

Parameters
notification the notification to schedule.
date a date in the future
Throws
NullPointerException if a parameter is null

public void schedule (Notification notification, int interval)

Schedules a Notification periodically.

Warning: If the application is in foreground state (visible to the end-user), then the notification will not be displayed at the status bar, only the callback method onLocalNotificationReceived will be called.

NB. the time interval between notification trigger is not very accurate and can vary from some seconds to around several minutes on some platforms.

Parameters
notification the notification to schedule
interval time interval in minutes
Throws
NullPointerException if a parameter is null

public void showNotification (Notification notification)

Shows the Notification in the status bar no matter if the application is in background or in foreground.

Limitations

In iOS, this method has the same effect as notify(Notification).

Parameters
notification the notification to show
Throws
NullPointerException if the parameter is null