title | url | weight | description | tags | |||||
---|---|---|---|---|---|---|---|---|---|
Send Notifications to Multiple Devices |
/howto8/mobile/notif-mult-devices/ |
71 |
Learn to send notifications to multiple devices with the Native Mobile Builder. |
|
This tutorial teaches you how to send test push notifications to multiple devices.
{{% alert color="info" %}} 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. {{% /alert %}}
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 Build a Mendix Native App in the Cloud through the end of the Making Your First Build section
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.
Create a microflow ACT_SendProductToAllDevices with the following elements:
{{< figure src="/attachments/howto8/mobile/native-mobile/notifications/notif-mult-devices/SendProductToAll.png" alt="SendProductToAll" width="300" class="no-border" >}}
-
Add a Product data parameter to your microflow.
-
Retrieve the PushNotifications.Device entity list from a database:
{{< figure src="/attachments/howto8/mobile/native-mobile/notifications/notif-mult-devices/retrieveDevices.png" alt="retrieveDevices" width="300" class="no-border" >}}
-
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:
{{< figure src="/attachments/howto8/mobile/native-mobile/notifications/notif-mult-devices/prepareMessageData.png" alt="prepareMessageData" width="300" class="no-border" >}}
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:
{{< figure src="/attachments/howto8/mobile/native-mobile/notifications/notif-mult-devices/sendMessagesJava.png" alt="sendMessagesJava" width="300" class="no-border" >}}
- Message data param: $MessageToBeSent.
-
Go to Product_NewEdit and drag ACT_SendProductToAllDevices into that page's data view:
{{< figure src="/attachments/howto8/mobile/native-mobile/notifications/notif-mult-devices/sendProductToAllButton.png" alt="sendProductToAllButton" width="300" class="no-border" >}}
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.
For more detail on Java actions available in the Push notifications module, see the sections below.
This allows users to create their own user interfaces in order to alter and create a push notification message.
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
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.
If you run into issues, see the Troubleshoot Notification Issues section of Send Your First Test Push Notification.