public class LocalNotification extends Object
Local notifications are user notifications that are scheduled by the app itself. They are very similar to push notifications, except that they originate locally, rather than remotely.
They enable an app that isnt running in the foreground to let its users know it has information for them. The information could be a message, an impending calendar event, or new data on a remote server. They can display an alert message or they can badge the app icon. They can also play a sound when the alert or badge number is shown.
When users are notified that the app has a message, event, or other data for them, they can launch the app and see the details. They can also choose to ignore the notification, in which case the app is not activated.
This class encapsulates a single notification (though the notification can be repeating).
Android Note: The default image that is used on the android top status bar and on the notification itself is the App's icon. However Android 5 and above will only display this image as a silhouette using alpha pixels. This will result in many icons appearing to be a blank white square. In such cases you can provide an alternate image to be displayed instead. Place a 24x24 image named "ic_stat_notify.png" in your project's native/android directory, and this image will be used instead.
Modifier and Type | Field and Description |
---|---|
static int |
REPEAT_DAY
Constant used in
#setRepeatType(int) to indicate that this
notification should be repeated every day. |
static int |
REPEAT_HOUR
Constant used in
#setRepeatType(int) to indicate that this
notification should be repeated every hour. |
static int |
REPEAT_MINUTE
Constant used in
#setRepeatType(int) to indicate that this
notification should be repeated every 1 minute. |
static int |
REPEAT_NONE
Constant used in
#setRepeatType(int) to indicate that this
notification should not be repeated. |
static int |
REPEAT_WEEK
Constant used in
#setRepeatType(int) to indicate that this
notification should be repeated every week. |
Constructor and Description |
---|
LocalNotification()
Creates a new local notification
|
Modifier and Type | Method and Description |
---|---|
String |
getAlertBody()
Gets the alert body to be displayed for this notification.
|
String |
getAlertImage()
Gets the notification image
|
String |
getAlertSound()
Gets the alert sound to be sounded when the notification arrives.
|
String |
getAlertTitle()
Gets the alert title to be displayed for this notification.
|
int |
getBadgeNumber()
Gets the badge number to set for this notification.
|
String |
getId()
Gets the ID of the notification.
|
boolean |
isForeground()
Checks whether this notification will be displayed in the device's notification center even when the app is in the foreground.
|
void |
setAlertBody(String alertBody)
Sets the alert body to be displayed for this notification.
|
void |
setAlertImage(String image)
Sets an image to be displayed on the platform notifications bar, if the underlying platform
supports image displaying otherwise the image will be ignored.
|
void |
setAlertSound(String alertSound)
Sets the alert sound to be sounded when the notification arrives.
|
void |
setAlertTitle(String alertTitle)
Sets the alert title to be displayed for this notification.
|
void |
setBadgeNumber(int badgeNumber)
Gets the badge number to set for this notification.
|
void |
setForeground(boolean foreground)
Set whether this notification should be displayed in the device's notification center even when the app is
in the foreground.
|
void |
setId(String id)
Sets the ID of the notification.
|
public static final int REPEAT_NONE
#setRepeatType(int)
to indicate that this
notification should not be repeated.public static final int REPEAT_MINUTE
#setRepeatType(int)
to indicate that this
notification should be repeated every 1 minute.public static final int REPEAT_HOUR
#setRepeatType(int)
to indicate that this
notification should be repeated every hour.public static final int REPEAT_DAY
#setRepeatType(int)
to indicate that this
notification should be repeated every day.public static final int REPEAT_WEEK
#setRepeatType(int)
to indicate that this
notification should be repeated every week.public int getBadgeNumber()
public void setBadgeNumber(int badgeNumber)
badgeNumber
- the badgeNumber to setpublic String getAlertBody()
public void setAlertBody(String alertBody)
alertBody
- the alertBody to setpublic String getAlertTitle()
public void setAlertTitle(String alertTitle)
alertTitle
- the alertTitle to setpublic String getAlertSound()
public void setAlertSound(String alertSound)
LocalNotification n = new LocalNotification();
n.setAlertSound("/notification_sound_bells.mp3");
alertSound
- the alertSound to setpublic String getId()
LocalNotificationCallback.localNotificationReceived(java.lang.String)
so you can use it as a lookup key to retrieve the rest of the information as required
from storage or some other mechanism.
The ID can also be used to cancel the notification later using Display.cancelLocalNotification(java.lang.String)
public void setId(String id)
LocalNotificationCallback.localNotificationReceived(java.lang.String)
so you can use it as a lookup key to retrieve the rest of the information as required
from storage or some other mechanism.
The ID can also be used to cancel the notification later using Display.cancelLocalNotification(java.lang.String)
id
- the id to setpublic String getAlertImage()
public void setAlertImage(String image)
image
- a path to the image, the image needs to be placed in the app root.public void setForeground(boolean foreground)
foreground
- True to display this notification in the notification center even when the app is in the foreground.public boolean isForeground()