Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Nowadays smartphones are increasingly considered a key part of any digital solution. Their increased computing capacities and the higher speed of Internet connections , allow enable a new horizon of connected applications. Some IoT applications today use smartphones as gateways, but it is also normal to use the smartphone as a notification and awareness tool in some cases where speed is key.

That is why we have developed a new node for the onesait Platform Flow Engine: onesaitplatform-firebase-notification. This node has integration with Firebase. Firebase is a Google platform that helps developers manage the backend of their mobile appsapplications. Some of the features of the platform are open to everyone, and that is the case of the cloud messaging function.

...

This article shows an example of native notifications for Android applications using the onesait Platform 's Flow Engine. The guide will highlight the process required to carry out the example using the onesait Platform modules, while the Firebase-specific task will only be mentioned and but not explained in detail. Please contact us for additional information on how to integrate your mobile app within the Firebase platform.

...

The behavior of the application is the followingas follows:

  1. First, after once the app is installed, the app it connects to Firebase and is given a Device Token. This token is unique to the Android device, although it can be updated later. It is advisable to monitor these changes using the callback inside the onNewToken method of your class, which extends FirebaseMessagingService.

  2. Every time a new token is granted, or when the user clicks the REGISTER DEVICE TOKEN button, the granted given token is sent to the onesait Platform. These token keys are stored in the NativeNotifKeys ontology, which looks like this (For this example, the app application will be a messaging application, and the user will be the IMEI code of the host smartphone):

  3. To perform step 2, the NativeNotifKeys ontology must be created (they it already exist exists in the demo environment), and an API endpoint will be created in the environment. This API will publish this ontology via a URL, with INSERT capabilities. For this example, this is what the API definition looks like:

  4. Now the app, which already has a valid Firebase token, has replicated this information to in the onesait Platform, allowing developers to take advantage of this data and send notifications to these devices. But we you still have yet to enable a way to push messages through the onesait Platform to end devices. That is why we you must define this ontology, to record incoming messages:

    Image RemovedImage Added
  5. After the creation of the ontology, we you have to define the rule to send the messages inserted in the notificationMessage ontology to the end devices. We will use Use the onesait Platform Flow Engine module to perform this operation:

    Image RemovedImage Added
  6. The first block only inserts notification message in the platform. The second block then uses a onesaitplatform-notification-endpoint node to subscribe to the above previous inserts in the notificationMessage ontology. This node will insert the message in the onesaitplatform-firebase-notification node, which handles the Firebase integration for the demo app.

  7. With the flow set upconfigured, and before we start sending starting to send notifications, we will next let’s explore two different types of messages that we have integrated into the example:

    1. Notification to a single, specific device.

    2. Notification to all devices subscribed to a specific theme (or topic).

  8. To change this behavior, there is a topic field within the notificationMessage ontology. If it is blank ("topic":""), then the firebase-notification node will send this notification to the device corresponding to the user field within the message, using the current Firebase token updated by the app via the NativeNotifKeys API. These are the message, the output of the Flow Engine and how the notification appears on the mobile phone:

...

The notification appears quickly with the title and body that we you define in the ontology instance. Firebase claims that over 95% of the notifications they send, are delivered within a 250-milisecond interval.

The last step will be to send notifications to a group of devices subscribed to a certain theme. For To do that, first you have to go to the app and press the SUBSCRIBE TO NEWS button:

...

And then change the topic to news inside the stream engine embednews” in the flow engine insertion:

...

For To test the theme-based notifications, it is best to install the sample app on more than one phone so you can see the difference. From one phone, the result will be the arrival of the notification:

...