All Products
Search
Document Center

Mobile Platform as a Service:Process notification clicks

Last Updated:Jan 29, 2023

For the apps which have third-party channels integrated and run on the corresponding vendors’ mobile phones, the server pushes messages through the third-party channels by default; for other apps, the server pushes messages through the self-built channel.

  • When self-built channel receives a message, the push SDK automatically deliver a notification, and the user can click it to open the Web page.

    Important

    Message notification IDs used by the SDK start from 10000. Make sure that other notification IDs you use do not conflict with them.

  • To jump to an in-app page, refer to Implement in-app page redirection.

  • To process the received messages by yourself, refer to Implement custom message processing.

  • After the third-party channel receives a message, the mobile system will automatically deliver a notification. Neither the push SDK nor developers can interfere. The push SDK can receive the message and open the Web page only when the user clicks the notification.

  • To jump to an in-app page, refer to Implement in-app page redirection.

  • To process the redirection upon click on message by yourself, refer to Implement custom message processing.

Prerequisites

  • The MPPushMsgServiceAdapter method mentioned in this guide is only applicable for baseline 10.1.68.32 or later version. If your current baseline version is lower than 10.1.68.32, refer to mPaaS upgrade guide to upgrade the baseline.

  • You can continue using the AliPushRcvService method in the earlier version. Click here to download the documentation about using AliPushRcvService.

Implement in-app page redirection

If you need to jump to a specific page in the app, you can fill in a custom DeepLink in the redirection address of the message, for example: mpaas://navigate, and set up a routing Activity in the app to receive the DeepLink and then distribute it to other pages.

You also need to add the corresponding intent-filter in AndroidManifest.xml for the routing Activity, for example:

<activity android:name=".push.LauncherActivity"
    android:launchMode="singleInstance">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="mpaas" />
    </intent-filter>
</activity>

Obtain URI and message from the routing Activity.

Uri uri = intent.getData();
MPPushMsg msg = intent.getParcelableExtra("mp_push_msg");

Implement custom message processing

To process the messages by yourself, you can override the onMessageReceive and onChannelMessageClick method of MPPushMsgServiceAdapter.

public class MyPushMsgService extends MPPushMsgServiceAdapter {

    /**
     * Callback after the self-built channel receives the message
     *
     * @param msg Message received
     * @return Whether the message has been processed:
     * If true is returned, the SDK will not process the message; the developer needs to process the message, including notification delivery and redirection upon click on notification. 
     * If false is returned, the SDK will automatically deliver a notification and add the redirection upon click on notification.
     */
    @Override
    protected boolean onMessageReceive(MPPushMsg msg) {
        Log.d("Receive message through self-built channel:" + msg.toString());
        // Process the message by yourself, such as delivering custom notification
        return true;
    }

    /**
     * Callback after the notification is clicked. The messages delivered through the third-party channels are displayed on the notification bar.
     *
     * @param msg Message received
     * @return Whether the click on message has been processed:
     * If true is returned, the SDK will not process the click on notification delivered through the third-party channel; the developer needs to process the redirection upon click on notification.
     * If false is returned, the SDK will automatically process the redirection upon click on notification.

     */
    @Override
    protected boolean onChannelMessageClick(MPPushMsg msg) {
        Log.d("Message through the third-party channel is clicked:" + msg.toString());
        // Process the logic after the message is clicked by yourself
        return true;
    }

}

MPPushMsg encapsulates all the parameters of the message:

String id = msg.getId(); // Message ID
boolean isSilent = msg.isSilent(); // Whether to silence the message

String title = msg.getTitle(); // Message title
String content = msg.getContent(); // Message body

String action = msg.getAction(); // Redirection type, 0: URL, 1: Custom DeepLink
String url = msg.getUrl(); // Redirection address, URL or DeepLink

int pushStyle = msg.getPushStyle(); // Message type, 0: Normal message, 1: Big text, 2: Rich text
String iconUrl = msg.getIconUrl(); // Icon of rich text message
String imageUrl = msg.getImageUrl(); // Large image of rich text message

String customId = msg.getCustomId(); // Custom message ID
String params = msg.getParams(); // Extension parameters

After you process the message, you may need to report the following message tracking, otherwise the MPS usage analysis module on the mPaaS console will not get accurate statistical data.

MPPush.reportPushOpen(msg); // Report that the message was opened
MPPush.reportPushIgnored(msg); // Report that the message was ignored

For the messages delivered through self-built channel:

  • For silent messages, there is no need to report the message tracking.

  • For non-silent messages, it is required to report the opened and ignored messages. You can listen the message opening and ignorance by calling the SetContentIntent and setDeleteIntent methods of Notification.Builder or through other effective methods.

For the messages delivered through the third-party channels, there is no need to report the message tracking by yourself.