Notification Manager API
The HERE Notification Manager API enables platform applications to intercept HTML5 notifications raised by HERE apps in windows or views and route them to a custom notification manager, such as HERE Notification Center, rather than the operating system's default notification system.
The Web Notifications API specification is unopinionated regarding how notifications should be shown to the user. Most general-purpose web browsers use the operating system's notification mechanism, but doing so is not required by the specification.
The Notification Manager API does not create any user interface; it assumes that the custom notification manager provides the UI.
See Using the Notifications API, on MDN for details on how to raise HTML5 notifications in an app.
This functionality is experimental and subject to change. This implementation does not support notifications that are raised using service workers.
How it works
A platform application calls NotificationManager.init()
to create an instance of NotificationManagerInstance
, which intercepts web notifications.
It then sets a handler on the notification manager, which handles notification events, show
, click
, and close
.
The handler is invoked by events on a web notification.
Only one notification manager can exist for a platform application at a given time; calling init()
fails if a notification manager is already running.
API permissions
Both the Web Notifications API and the HERE Notification Manager API are secured APIs in HERE Core.
The platform application must have the NotificationManager.init
permission in order to define a notification manager.
Web apps must have the notifications
permission in order to raise HTML5 notifications while running in a HERE Core platform.
These permissions must be declared in each application's manifest and must be granted by the desktop owner or their delegate.
Refer to API security for details.
How to use the API
Using the Notification Manager API consists of several steps.
- Initialize the notification manager.
- Set up notification event handling.
- Handle notification interactions.
- Clean up the notification manager when it is no longer needed.
Initialize the notification manager
Create a notification manager instance in the platform application.
const notificationManager = await fin.NotificationManager.init();
Set up notification event handling
Configure the notification manager to process notifications.
notificationManager.setNotificationHandler((webNotification) => {
console.log(`Notification received: ${webNotification.properties.title}`);
console.log(`From: ${new URL(webNotification.url).origin}`);
// Route to your notification system
displayInNotificationUI(webNotification);
// Notify the originating app that the notification was shown
notificationManager.dispatch({
type: 'show',
notificationId: webNotification.notificationId
});
})
Handle notification interactions
When users interact with notifications, dispatch the events back to the originating HERE app:
// When user clicks a notification
notificationManager.dispatch({
type: 'click',
notificationId: notification.notificationId
});
// When user closes/dismisses a notification
notificationManager.dispatch({
type: 'close',
notificationId: notification.notificationId
});
Clean up the notification manager
Destroy the notification manager instance when the platform no longer needs to intercept HTML5 notifications.
await notificationManager.destroy();
After calling destroy()
, you can initialize a new notification manager if needed.