Send Notifications to Multiple Devices

Last update: Edit

1 Introduction

This tutorial will teach you to send test push notifications to multiple devices.

2 Prerequisites

Before starting this how-to, make sure you have completed the following prerequisite:

If you want to use push notifications with custom apps created with Mendix Native Mobile Builder, make sure you have completed the following prerequisite:

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:

SendProductToAll
  1. Add a Product data parameter to your microflow.
  2. Retrieve the PushNotifications.Device entity list from a database:

    retrieveDevices
  3. 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:

    prepareMessageData

    ContextObjectGuid is set to empty since you will pass the object itself to the SendMessageToDevices Java action where it will be retrieved automatically.

  4. 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:

    sendMessagesJava
  5. Go to Product_NewEdit and drag and drop ACT_SendProductToAllDevices inside of that page’s data view:

    sendProductToAllButton

3.2 Testing the Implementation

Test your new push notification capabilities by doing the following:

  1. Run your native app in your device’s background.
  2. 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.

6 Read More