Local Notifications
Local notifications are scheduled by an app and delivered on the same device. They are suited for apps with time-based behaviors, such as calendar events.
When you run your app on a device with Android OS 8.0 or above, Volt MX uses default channels that are mentioned in the localnotificationconfig.xml file.
Note: Each app on a device is limited to 64 scheduled local notifications. The system discards scheduled notifications exceeding this limit. Recurring notifications are treated as a single notification.
The local notification system consists of the following namespace and related functions:
Initializing Local Notifications
To initialize your app to receive local notifications, it must invoke the voltmx.localnotifications.setCallbacks function in the Notifications API and pass it the callback handler functions. The following sample code demonstrates how to initialize local notifications.
Creating Local Notifications
Your app creates local notifications that are triggered then their corresponding events occur.
Note: The local notification API, voltmx.localnotification.create
• Can be called directly in Android devices.
• In iOS devices you must first call voltmx.notificationsettings.registerCategory API in order to call the create API.
Canceling Local Notifications
To stop receiving local notifications, your all calls the voltmx.localnotifications.cancel function, as shown in the code sample below.
Creating Actions and Categories
Your app can create categories of notifications and set actions for those categories. To do so, it call the voltmx.notificationsettings.registerCategory function, as illustrated in the following sample code.
Important Consideration for Android Platform
The default settings are located in the localnotificationconfig.xml file (available after the application is built) in the ‘dist{APP-ID}\res\values’ location. You can modify these settings by using a regular expression replacement task that is written in the androidprecompiletask.xml file.
For example, if you want to update the value of the ‘notify_local_msg_notifications_count’ key from ‘1’ to ‘5 ‘, you must use the following code snippet, which replaces the value directly in the file.
Similarly, you can configure other keys by using the androidprecompiletask.xml file.
Modifying localnotificationconfig.xml File in Android Platform
The default behavior of the local notification message can be customized by modifying the localnotificationconfig.xml file. The localnotificationconfig.xml file contains key value pairs that allow applications to configure individual keys to override the default behavior.
You can customize the notification using the keys provided in localnotificationconfig.xml.
The table below shows a list of key value pairs, each with a brief description.
Notification ID | Default Value | Description |
---|---|---|
notify_local_msg | true | Enable or disable new local message notifications. If false, no status bar notification is shown when application is running in background. |
notify_local_msg_channel_title | Local Notifications | Channel title for local notifications. |
notify_local_msg_channel_desc | All local notifications will be displayed under this category | Channel description for local notifications. |
notify_local_msg_notifications_count | 1 | By default, only the latest local message notification is kept in the status bar. Use this option to control the number of messages to be stored. The maximum limit allowed in Android is 50. > Note: After exceeding the storage limit, older messages are replaced with newer messages. However, sometimes older notifications are replaced with newer messages even before the storage reaches the specified count (this happens when the app is closed by the Android system). |
notify_local_msg_icon | icon | Specify icon resource without extension. For example, set a logo to use an image for the message icon for which the file name is logo.png. The default is icon.png. |
notify_local_msg_sound | true | Enable or disable sound for local message notification. |
notify_local_msg_vibrate | true | Enable or disable vibrate for local message notification. |
notify_local_msg_lights | true | Enable or disable lights for local message notification. |
notify_local_msg_clear | true | Indicates if a user can clear the unread local message notification. |