Part 8: Send Notifications to Multiple Devices
Introduction
This how-to teaches you how to send test push notifications to multiple devices.
Prerequisites
Before starting this section, make sure you have completed the following prerequisite:
- Send one test push notification as described in Push Notifications
If you want to use push notifications with custom apps created with Mendix Native Mobile Builder, make sure you have completed the following prerequisite:
- Complete Build a Mendix Native App Locally
Sending Notifications to Multiple Devices
What if you want to send messages to all your users’ devices with a single button push, but you do not want to handle the GUID retrieval? The section below will address this scenario. Specifically, you will send a push notification containing a data object to your users’ devices via the Push Notifications API.
Creating a Microflow to Send a Data Object Push Notification
Create a microflow ACT_SendProductToAllDevices with the following elements:
-
Add a Product data parameter to your microflow.
-
Retrieve the PushNotifications.Device entity list from a database:
-
Drag the PrepareMessageData microflow from PushNotifications/_USE ME/API onto ACT_SendProductToAllDevices and configure the following:
- Title: myTitle.
- Body: myBody.
- TimeToLive: 0.
- Badge: 0.
- ActionName: sendProduct.
- ContextObjectGuid: empty:
ContextObjectGuid is set to empty since you will pass the object itself to the SendMessageToDevices Java action where it will be retrieved automatically.
- Title: myTitle.
-
Drag the SendMessageToDevices Java action from PushNotifications/_USE ME/API onto ACT_SendProductToAllDevices and configure the following:
- Message data param: $MessageToBeSent.
- Device param: $Devices.
- Context object: $Product:
- Message data param: $MessageToBeSent.
-
Go to Product_NewEdit and drag ACT_SendProductToAllDevices inside of that page’s data view:
Testing the Implementation
Test your new push notification capabilities by doing the following:
- Run your native app in your device’s background.
- In your web browser, go to Product_NewEdit and click your ACT_SendProductToAllDevices microflow button.
This will send a notification to all available devices. When you tap the notification, you will be redirected to the particular product page you modeled.
More Java Action Explanations
For more detail on Java actions available in the Push notifications module, see the sections below.
PrepareMessageData Microflow
This allows users to create their own user interfaces in order to alter and create a push notification message.
SendMessageToDevice and SendMessageToDevices Java Actions
These Java actions have the following parameters:
- MessageDataParam (PushNotifications.MessageData): this parameter can be generated by the PrepareMessageData microflow
- DeviceParam (List of PushNotifications.Device or PushNotification.Device): this parameter can be used to send the same message to a list of devices
- ContextObject: this parameter will allow any Mendix object to be passed to the notification
SendMessageToUsers and SendMessageToUser Java Actions
Every user is allowed to have more than one device. When sending push notifications to every device of a particular user, use the SendMessageToUser Java action.
To send a push notification to all users, use the SendMessageToUsers Java action.
Troubleshooting Notification Issues
If you run into issues, see the Troubleshoot Notification Issues section of Send Your First Test Push Notification.