Integration scenarios for third-party channels

更新时间:
复制 MD 格式

This document describes a scenario that combines standard push notifications with auxiliary pop-up notifications and explains how to configure the auxiliary pop-up feature.

Client configuration

The client has two activities: `Main` and `Second`. `MainActivity` is the home page that opens on app startup. `SecondActivity` extends `AndroidPopupActivity`.

  • Configure the standard notification callback

    public class MyMessageReceiver extends MessageReceiver {
      /**
      * Callback method for push notifications.
      * @param context
      * @param title
      * @param summary
      * @param extraMap
      */
      @Override
      public void onNotification(Context context, String title, String summary, Map<String, String> extraMap) {
        Log.d(TAG, "Receive notification, title: " + title + ", content: " + summary + ", extraMap: " + extraMap);
      }
    }
  • Define `MainActivity`:

    package com.alibaba.push.testdemo;
    public class MainActivity extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "Main");
      }
    }
  • Define `SecondActivity`:

    package com.alibaba.push.testdemo;
    import com.alibaba.sdk.android.push.AndroidPopupActivity;
    public class SecondActivity extends AndroidPopupActivity {
      /**
       * Callback for opening a specified activity from an auxiliary pop-up.
       * @param title     Title
       * @param content   Content
       * @param extraMap  Extra parameters
       */
      @Override
      protected void onSysNoticeOpened(String title, String content, Map<String, String> extraMap) {
          Log.d(TAG, "Receive XiaoMi notification, title: " + title + ", content: " + content + ", extraMap: " + extraMap);
      }
    }

Scenario: Standard push + auxiliary pop-up

Server-side configuration

Configure the server as follows:

PushRequest pushRequest = new PushRequest();
// Other settings are omitted.
// Notification
pushRequest.setPushType("NOTICE");
// Title
pushRequest.setTitle("hello");
// Content
pushRequest.setBody("PushRequest body");
// Action after a notification is tapped. "APPLICATION": Opens the app. "ACTIVITY": Opens an Android activity. "URL": Opens a URL. "NONE": No action.
pushRequest.setAndroidOpenType("APPLICATION");
// The activity to open. This parameter is valid only when AndroidOpenType is set to "Activity".
pushRequest.setAndroidActivity("com.alibaba.push.testdemo.MainActivity"); 
// Set the activity to open from the auxiliary pop-up.
pushRequest.setAndroidPopupActivity("com.alibaba.push.testdemo.SecondActivity");
// Set the title for the auxiliary pop-up notification.
pushRequest.setAndroidPopupTitle("hello2");
// Set the content for the auxiliary pop-up notification.
pushRequest.setAndroidPopupBody("PushRequest body2");
// Set the extended properties for notifications on Android devices.
pushRequest.setAndroidExtParameters("{\"k1\":\"android\",\"k2\":\"v2\"}");

Push results

Third-party channel devices and online devices:

  • A notification is delivered through the standard push channel. When you tap the notification, the app opens to the `MainActivity` home page. If the app is already in the foreground, the current screen remains unchanged.

  • The `onNotification()` callback outputs `Receive notification, title: hello, content: PushRequest body, extraMap: {k1=android, k2=v2}`.

For devices that use third-party channels, such as Xiaomi and Huawei, after the app process is terminated:

  • A notification is displayed through the third-party channel. When you tap the notification, `SecondActivity` opens.

  • The `onSysNoticeOpened()` callback outputs `Receive XiaoMi notification, title: hello, content: PushRequest body, extraMap: {k1=android, k2=v2}`.

Scenario summary

Server-side parameters

  • The `Title`, `Body`, and `AndroidExtparameters` parameters apply in all scenarios.

  • The `AndroidOpenType` and `AndroidActivity` parameters apply to online devices and devices that do not use third-party channels, such as Xiaomi and Huawei.

  • The `AndroidPopupTitle`, `AndroidPopupBody`, and `AndroidPopupActivity` parameters apply only to third-party channels.

Client-side data reception

  • For online devices and devices that do not use third-party channels, such as Xiaomi and Huawei, data is received by the custom `MessageReceiver`.

  • For third-party channels, data is received by the auxiliary pop-up `AndroidPopupActivity`.

Note

When a notification is delivered through a third-party channel, its title and content are derived from the `AndroidPopupTitle` and `AndroidPopupBody` values set on the server. When a user taps the notification, the `AndroidPopupActivity` opens. The `onSysNoticeOpened` callback then receives the values of the `Title`, `Body`, and `AndroidExtParameters` parameters.