Auxiliary pop-up integration

更新时间:
复制 MD 格式

This topic describes how to use auxiliary pop-ups after you integrate with third-party channels.

Introduction

After a third-party channel receives a push notification and displays it in the system notification bar, the auxiliary pop-up helps developers process the push data. This includes:

  • Decrypting push data

  • The pushed plaintext data is then passed to the app for processing.

For information about how to integrate auxiliary pop-ups into your app, see App integration.

For information about how to send push notifications from the backend through third-party channels, see Server-side configuration.

Preparations

App integration assistant dialog

1. Create a custom activity for auxiliary pop-ups

1.1 Create a custom transit activity for auxiliary pop-ups

Important
  • This method uses a custom activity as a transit activity to retrieve extra push parameters. The extra parameters must contain the routing information for the target activity.

  • Use this method to open multiple activity pages from push notifications.

  • When you send a push notification, set the page to open to the transit activity that you created. The routing information for the actual target activity must be configured in the extra parameters.

  1. Create a custom activity that inherits from AndroidPopupActivity or implements PopupNotifyClick.

  2. Implement the onSysNoticeOpened abstract method of AndroidPopupActivity. This is a callback method that is invoked after the push data is successfully decrypted. In this method, you can retrieve the notification title, content, and extra parameters. You can use these parameters to navigate to a specific activity.

  3. Override the onNotPushData method of AndroidPopupActivity. This is a callback method that is invoked when no push data is retrieved.

  4. Override the onParseFailed method of AndroidPopupActivity. This is a callback method that is invoked when the push data fails to be decrypted.

Method 1: Create a custom activity that inherits from AndroidPopupActivity
import android.content.Intent
import android.os.Bundle
import com.alibaba.sdk.android.push.AndroidPopupActivity

class PopupPushActivity : AndroidPopupActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    /**
     * Implement the notification open callback method to get notification information.
     * @param title     Title
     * @param summary   Content
     * @param extMap    Extra parameters
     */
    override fun onSysNoticeOpened(title: String, summary: String, extMap: Map<String, String>) {
        //TODO: Get push parameters and navigate to the specified page.
        finish()
    }

    /**
     * Callback for when the data is not push data.
     *
     * @param intent
     */
    override fun onNotPushData(intent: Intent) {
        super.onNotPushData(intent)
        finish()
    }

    /**
     * Callback for when the data is push data but decryption fails.
     *
     * @param intent
     */
    override fun onParseFailed(intent: Intent) {
        super.onParseFailed(intent)
        finish()
    }
}
import android.content.Intent;
import android.os.Bundle;

import com.alibaba.sdk.android.push.AndroidPopupActivity;

import java.util.Map;

public class PopupPushActivity extends AndroidPopupActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    /**
     * Implement the notification open callback method to get notification information.
     * @param title     Title
     * @param summary   Content
     * @param extMap    Extra parameters
     */
    @Override
    protected void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
        //TODO: Get push parameters and navigate to the specified page.
        finish();
    }

    /**
     * Callback for when the data is not push data.
     *
     * @param intent
     */
    @Override
    public void onNotPushData(Intent intent) {
        super.onNotPushData(intent);
        finish();
    }

    /**
     * Callback for when the data is push data but decryption fails.
     *
     * @param intent
     */
    @Override
    public void onParseFailed(Intent intent) {
        super.onParseFailed(intent);
        finish();
    }
}
Method 2: Create a custom activity that implements PopupNotifyClick
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.alibaba.sdk.android.push.popup.OnPushParseFailedListener
import com.alibaba.sdk.android.push.popup.PopupNotifyClick
import com.alibaba.sdk.android.push.popup.PopupNotifyClickListener


class PopupPushActivity : Activity(), PopupNotifyClickListener,
    OnPushParseFailedListener {
    private val mPopupNotifyClick = PopupNotifyClick(this)
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mPopupNotifyClick.onCreate(this, intent)
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        mPopupNotifyClick.onNewIntent(intent)
    }

    /**
     * Implement the notification open callback method to get notification information.
     * @param title     Title
     * @param summary   Content
     * @param extMap    Extra parameters
     */
    override fun onSysNoticeOpened(title: String, summary: String, extMap: Map<String, String>) {
        //TODO: Get push parameters and navigate to the specified page.
        finish()
    }

    /**
     * Callback for when the data is not push data.
     *
     * @param intent
     */
    override fun onNotPushData(intent: Intent) {
        finish()
    }

    /**
     * Callback for when the data is push data but decryption fails.
     *
     * @param intent
     */
    override fun onParseFailed(intent: Intent) {
        finish()
    }
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.alibaba.sdk.android.push.popup.OnPushParseFailedListener;
import com.alibaba.sdk.android.push.popup.PopupNotifyClick;
import com.alibaba.sdk.android.push.popup.PopupNotifyClickListener;

import java.util.Map;

public class PopupPushActivity extends Activity implements PopupNotifyClickListener, OnPushParseFailedListener {
    private final PopupNotifyClick mPopupNotifyClick = new PopupNotifyClick(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPopupNotifyClick.onCreate(this, getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        mPopupNotifyClick.onNewIntent(intent);
    }

    /**
     * Implement the notification open callback method to get notification information.
     * @param title     Title
     * @param summary   Content
     * @param extMap    Extra parameters
     */
    @Override
    public void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
        //TODO: Get push parameters and navigate to the specified page.
        finish();
    }

    /**
     * Callback for when the data is not push data.
     *
     * @param intent
     */
    @Override
    public void onNotPushData(Intent intent) {
        finish();
    }

    /**
     * Callback for when the data is push data but decryption fails.
     *
     * @param intent
     */
    @Override
    public void onParseFailed(Intent intent) {
        finish();
    }
}

1.2 Implement auxiliary pop-ups in an existing activity

Important
  • This method implements the auxiliary pop-up directly in an existing activity. Tapping the push notification opens the existing activity directly.

  • You can also use this method to open a small number of activity pages from push notifications.

  • When you send a push notification, set the page to open to the activity where the auxiliary pop-up is implemented.

App developers usually have their own BaseActivity. This section only describes how to use PopupNotifyClick to implement an auxiliary pop-up.

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.alibaba.sdk.android.push.popup.OnPushParseFailedListener
import com.alibaba.sdk.android.push.popup.PopupNotifyClick
import com.alibaba.sdk.android.push.popup.PopupNotifyClickListener


class PopupPushActivity : Activity(), PopupNotifyClickListener,
    OnPushParseFailedListener {
    private val mPopupNotifyClick = PopupNotifyClick(this)
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mPopupNotifyClick.onCreate(this, intent)
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        mPopupNotifyClick.onNewIntent(intent)
    }

    /**
     * Implement the notification open callback method to get notification information.
     * @param title     Title
     * @param summary   Content
     * @param extMap    Extra parameters
     */
    override fun onSysNoticeOpened(title: String, summary: String, extMap: Map<String, String>) {
        //TODO: Get push parameters and process them based on your business needs.
        finish()
    }

    /**
     * Callback for when the data is not push data.
     *
     * @param intent
     */
    override fun onNotPushData(intent: Intent) {
        //TODO: No push data. This might be an abnormal call. Handle the exception.
    }

    /**
     * Callback for when the data is push data but decryption fails.
     *
     * @param intent
     */
    override fun onParseFailed(intent: Intent) {
        //TODO: Push data decryption failed. Handle the exception.
    }
}
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.alibaba.sdk.android.push.popup.OnPushParseFailedListener;
import com.alibaba.sdk.android.push.popup.PopupNotifyClick;
import com.alibaba.sdk.android.push.popup.PopupNotifyClickListener;

import java.util.Map;

public class PopupPushActivity extends Activity implements PopupNotifyClickListener, OnPushParseFailedListener {
    private final PopupNotifyClick mPopupNotifyClick = new PopupNotifyClick(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPopupNotifyClick.onCreate(this, getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        mPopupNotifyClick.onNewIntent(intent);
    }

    /**
     * Implement the notification open callback method to get notification information.
     * @param title     Title
     * @param summary   Content
     * @param extMap    Extra parameters
     */
    @Override
    public void onSysNoticeOpened(String title, String summary, Map<String, String> extMap) {
        //TODO: Get push parameters and process them based on your business needs.
        finish();
    }

    /**
     * Callback for when the data is not push data.
     *
     * @param intent
     */
    @Override
    public void onNotPushData(Intent intent) {
        //TODO: No push data. This might be an abnormal call. Handle the exception.
        
    }

    /**
     * Callback for when the data is push data but decryption fails.
     *
     * @param intent
     */
    @Override
    public void onParseFailed(Intent intent) {
        //TODO: Push data decryption failed. Handle the exception.
    }
}

2. Register the auxiliary pop-up activity

Register your custom auxiliary pop-up activity in the AndroidManifest.xml file. Add the registration under the application node.

<activity
    android:name="The fully qualified class name of the auxiliary pop-up activity"
    android:exported="true">
    
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="${applicationId}"
            android:path="/thirdpush"
            android:scheme="agoo" />
    </intent-filter>
    
</activity>
Important

android:exported=true must be configured.

Server-side configuration

You can use OpenAPI or the Alibaba Cloud Management Console for server-side configuration.

Important

When you use Mobile Push to send notifications through third-party channels, you must configure the following server-side parameters. If these parameters are not set, notifications are not sent to the third-party channels.

  1. OpenAPI push configuration

    • The advanced push API of OpenAPI 2.0 provides three parameters: AndroidPopupActivity, AndroidPopupTitle, and AndroidPopupBody. These parameters are used to set the activity to navigate to when the auxiliary pop-up notification is opened, the notification title, and the notification content, respectively. Note: The StoreOffline parameter must also be set to true.

    Note
    • The auxiliary pop-up takes effect only when an offline push notification is sent to a device through a third-party channel and the app's background process is cleared. This feature does not apply to devices that are not integrated with a third-party channel or to devices that are online.

    • When the auxiliary pop-up is active, the `Title`, `Body`, and `AndroidActivity` parameters, and functional settings in the extra parameters, such as sound and vibration, do not take effect.

    Server-side configuration example:

    PushRequest pushRequest = new PushRequest();
    // Other settings are omitted.
    // Notification
    pushRequest.setPushType("NOTICE");
    // Title
    pushRequest.setTitle(dateFormat.format(new Date()));
    // Body
    pushRequest.setBody("PushRequest body");
    // Extra parameters
    pushRequest.setAndroidExtParameters("{\"k1\":\"android\",\"k2\":\"v2\"}");
    // Set the activity to be opened by the auxiliary pop-up. Enter the class name, which must include the package name.
    pushRequest.setAndroidPopupActivity("*****");
    // Set the title for the auxiliary pop-up notification.
    pushRequest.setAndroidPopupTitle("*****");
    // Set the content for the auxiliary pop-up notification.
    pushRequest.setAndroidPopupBody("*****");
    // The message expires after 72 hours and will not be sent again.
    String expireTime = ParameterHelper.getISO8601Time(new Date(System.currentTimeMillis() + 72 * 3600 * 1000)); 
    pushRequest.setExpireTime(expireTime);
    // Specifies whether to save the offline message. If set to true, the user receives the message the next time they are online.
    pushRequest.setStoreOffline(true); 
    // When the push type is message, set this to true. If the device is offline, the message is automatically converted to a notification for the third-party channel.
    pushRequest.setAndroidRemind(true);
  2. Alibaba Cloud Management Console push configuration

    Log on to the Multiexperience Development Platform EMAS console. Select Mobile Push and then select your application. In the navigation pane on the left, choose Create Task > Push Notification. On the Third-party Channel Settings tab, configure the required parameters for the third-party channel, as shown in the following figure.