This tutorial will teach you to send test push notifications to multiple devices.
Push notifications only work with apps created through the Mendix Native Mobile Builder. You cannot send notifications to an app inside the Make it Native app.
Before starting this how-to, make sure you have completed the following prerequisite:
- Send one test push notification as described in Use 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 How to Deploy Your First Mendix Native Mobile App through the end of the Making Your First Build section
3 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.
3.1 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 and drop the PrepareMessageData microflow from PushNotifications/_USE ME/API onto ACT_SendProductToAllDevices and configure the following:
a. Title: myTitle.
b. Body: myBody.
c. TimeToLive: 0.
d. Badge: 0.
e. ActionName: sendProduct.
f. 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.
Drag and drop the SendMessageToDevices Java action from PushNotifications/_USE ME/API onto ACT_SendProductToAllDevices and configure the following:
a. Message data param: $MessageToBeSent.
b. Device param: $Devices.
c. Context object: $Product:
Go to Product_NewEdit and drag and drop ACT_SendProductToAllDevices inside of that page’s data view:
3.2 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.
4 More Java Action Explanations
For more detail on Java actions available in the Push notifications module, see the sections below.
4.1 PrepareMessageData Microflow
This allows users to create their own user interfaces in order to alter and create a push notification message.
4.2 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
4.3 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.
5 Troubleshoot Notification Issues
If you run into issues, see the Troubleshoot Notification Issues section of Send Your First Test Push Notification.