All Products
Search
Document Center

Process notification clicks

Last Updated: Jul 13, 2021

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.
    Notice: 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. Please submit a ticket or contact the mPaaS support staff to obtain the old version documents.

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:

 
  1. <activity android:name=".push.LauncherActivity"
  2. android:launchMode="singleInstance">
  3. <intent-filter>
  4. <action android:name="android.intent.action.VIEW" />
  5. <category android:name="android.intent.category.BROWSABLE" />
  6. <category android:name="android.intent.category.DEFAULT" />
  7. <data android:scheme="mpaas" />
  8. </intent-filter>
  9. </activity>

Obtain URI and message from the routing Activity.

 
  1. Uri uri = intent.getData();
  2. 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.

 
  1. public class MyPushMsgService extends MPPushMsgServiceAdapter {
  2. /**
  3. * Callback after the self-built channel receives the message
  4. *
  5. * @param msg Message received
  6. * @return Whether the message has been processed:
  7. * 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.
  8. * If false is returned, the SDK will automatically deliver a notification and add the redirection upon click on notification.
  9. */
  10. @Override
  11. protected boolean onMessageReceive(MPPushMsg msg) {
  12. Log.d("Receive message through self-built channel:" + msg.toString());
  13. // Process the message by yourself, such as delivering custom notification
  14. return true;
  15. }
  16. /**
  17. * Callback after the notification is clicked. The messages delivered through the third-party channels are displayed on the notification bar.
  18. *
  19. * @param msg Message received
  20. * @return Whether the click on message has been processed:
  21. * 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.
  22. * If false is returned, the SDK will automatically process the redirection upon click on notification.
  23. */
  24. @Override
  25. protected boolean onChannelMessageClick(MPPushMsg msg) {
  26. Log.d("Message through the third-party channel is clicked:" + msg.toString());
  27. // Process the logic after the message is clicked by yourself
  28. return true;
  29. }
  30. }

MPPushMsg encapsulates all the parameters of the message:

 
  1. String id = msg.getId(); // Message ID
  2. boolean isSilent = msg.isSilent(); // Whether to silence the message
  3. String title = msg.getTitle(); // Message title
  4. String content = msg.getContent(); // Message body
  5. String action = msg.getAction(); // Redirection type, 0: URL, 1: Custom DeepLink
  6. String url = msg.getUrl(); // Redirection address, URL or DeepLink
  7. int pushStyle = msg.getPushStyle(); // Message type, 0: Normal message, 1: Big text, 2: Rich text
  8. String iconUrl = msg.getIconUrl(); // Icon of rich text message
  9. String imageUrl = msg.getImageUrl(); // Large image of rich text message
  10. String customId = msg.getCustomId(); // Custom message ID
  11. 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.

 
  1. MPPush.reportPushOpen(msg); // Report that the message was opened
  2. 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.