logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Get the payload field

Note

This document is applicable for developing applications on the following platforms: iOS and Android.

Introduction

The offline push sender sends additional information to the receiver by configuring the payload parameter of ZIMPushConfig (the version before 2.5.0 is the extendedData parameter). When the receiver needs to use the ZPNs SDK, the payload in the extras of the push channel field to get this information.

This document introduces how to use the ZPNs SDK interface to obtain the payload transparent transmission field.

Warning

Before using the ZPNs SDK, please configure the ZIM offline push certificate in the ZEGO Admin Console (for details, please refer to Project Management- IM- Offline Push Configuration), If it cannot be configured, please contact ZEGO technical support.

Prerequisites

Before getting the payload transparent field, please make sure:

Common Usage

According to the push service provider of the offline push receiving end, developers should choose different ways to obtain the payload transparent transmission field, which are respectively listening to the notification of ZPNsEventHandler and obtaining it from the Activity in a native way.

Obtained through the ZPNsMessage object in the ZPNsEventHandler callback method

  1. Get the callback notification by implementing the method in ZPNsEventHandler:
Untitled
// For the support of the following interfaces by each push service provider, refer to the offline push document.
ZPNsEventHandler.onRegistered = (ZPNsRegisterMessage registerMessage) {};
ZPNsEventHandler.onNotificationArrived = (ZPNsMessage message) {};
ZPNsEventHandler.onNotificationClicked = (ZPNsMessage message) {};
ZPNsEventHandler.onThroughMessageReceived = (ZPNsMessage message) {};
1
Copied!
  1. Implement the following method as needed. When the above method is triggered, pass the ZPNsMessage object to this method and take out the payload field.
Untitled
String getZPNsMessagePayload(ZPNsMessage message) {
    return message.extras['payload'];
}
1
Copied!

Obtain from Activity (only supports Google FCM)

  1. In the AndroidManifest.xml file, set the exported attribute of the main Activity to true, and configure the intent-filter.
Untitled
<activity
    android:name="The main Activity path of your project"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
1
Copied!
  1. The developer obtains the data in the onCreate or onNewIntent of the main Activity through the following methods.
Untitled
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String payload = getIntent().getExtras().getString("payload");
}
1
Copied!

Previous

ResourcesID introduction

Next

Cross application offline push