Offline Push (Android)

Last updated: 2021-02-04 14:51:13

    Overview

    IM terminal users need to obtain the latest messages at any time. However, due to the limited performance and battery power of mobile devices, when the app is running in the background, IM recommends that you use the system-grade push channels provided by vendors for message notifications to avoid excessive resource consumption caused by maintaining a persistent connection. Compared with third-party push, system-grade push channels provide more stable system-grade persistent connections, enabling users to receive push messages at any time and greatly reducing resource consumption.

    IM currently supports Mi Push, Huawei Push, Meizu Push, vivo Push, OPPO Push, and Google FCM Push. The vendor channel dependencies used by IM are provided and maintained by TPNS in a unified manner, without the need for extra integration of vendor channels. After you add the vendor channel dependencies of TPNS, you can use the IM offline push feature. If you use only the IM offline push feature, no extra cost will be incurred. The vendor channels currently supported are as follows:

    Note:

    If you need to improve the push delivery rate or implement diversified push, we recommend that you install the SDK of TPNS to enjoy the complete push service. If you use IM and TPNS at the same time, you do not need to repeatedly integrate vendor channels.

    Push Channel System Requirements Conditions
    Mi Push MIUI To use Mi Push, add the dependency: implementation 'com.tencent.tpns:xiaomi:1.2.1.2-release'.
    Huawei Push EMUI To use Huawei Push, add the dependencies: implementation 'com.tencent.tpns:huawei:1.2.1.2-release' and implementation 'com.huawei.hms:push:5.0.2.300'.
    Google FCM Push Android 4.1 and later versions To use mobile phones installed with Google Play Services outside the Chinese mainland, add the dependency: implementation 'com.google.firebase:firebase-messaging:20.2.3'.
    Meizu Push Flyme To use Meizu Push, add the dependency: implementation 'com.tencent.tpns:meizu:1.2.1.2-release'.
    OPPO Push ColorOS Not all OPPO models and versions support OPPO Push. To use OPPO Push, add the dependency: implementation 'com.tencent.tpns:oppo:1.2.1.2-release'.
    vivo Push FuntouchOS Not all vivo models and versions support vivo Push. To use vivo Push, add the dependency: implementation 'com.tencent.tpns:vivo:1.2.1.2-release'.

    Here, “offline” means that the app is closed by the system or user without logging out. In such cases, if you want to receive IM SDK message reminders, you can integrate IM offline push.

    Note:

    • Users who have logged out or have been forced offline will not receive any message notifications.
    • For Mi and Huawei vendors, if a ChannelID has been configured on the official website of the vendor developer, you need to configure the same ChannelID on the IM console. Otherwise, push may fail. If you do not configure the ChannelID, you will be limited by the frequency limit.

    The process of implementing offline message push is as follows:

    1. Register with the vendor, apply to enable the push service and create an app. Obtain information such as AppID, AppKey, and AppSecret.
    2. Integrate the push SDK provided by the vendor with your project. Use the vendor’s console to test notification messages to ensure the SDK was integrated properly.
    3. Log in to the IM console and specify the push certificate and relevant information. The IM server will generate a unique certificate ID for each certificate.
    4. Send your certificate ID and device information to IM server.

    When the client app is killed by the system or user without IM logout, the IM server will push the messages sent by other accounts through vendor’s channel.

    Mi Push

    Configuring the push certificate

    1. Access the Mi open platform website to register an account and pass the developer verification. Log in to the console of the Mi open platform, choose App Service > Push Service, and create a MiPush service app. Take note of the Primary package name, AppID, and AppSecret information.

    2. Log in to the IM console and click the target app card to go to the basic configuration page of the app. Click Add a certificate under Android push configuration. Use the information you obtained in step 1 to configure the following parameters:

      • Push Platform: choose Mi.
      • Package name: the name of the MiPush service app.
      • AppID: enter the AppID you got from MiPush.
      • AppSecret: enter the AppSecret you got from MiPush.
      • Click event: the event to take place after the notification bar message is clicked. Valid values include Open app, Open URL, and Open specific app interface. For more information, see Configuring Click Event.
      • Open app* or Open specific app interface allows custom content pass through.

        Click OK to save the information. Take note of the ID of the certificate. Certificate information takes effect within 10 minutes after you save it.

    Integrating the push SDK

    1. Add the Mi dependency: implementation 'com.tencent.tpns:xiaomi:1.2.1.2-release'.
    2. Refer to the Integration Guide for Mi Push, and use the Mi console to test notification messages to ensure that the SDK was integrated properly.
    3. Call MiPushClient.registerPush to initialize the Mi Push service. After successful registration, you will receive the registration result in onReceiveRegisterResult of the custom BroadcastReceiver. regId is the unique identifier of the current app on the current device. After successful login to the IM SDK, you need to call setOfflinePushConfig to report the certificate ID and regId to the IM server.

    After the certificate ID and regId are successfully reported, the IM server sends messages via Mi Push notifications to the user when the app has been killed but the user has not logged out of IM.

    Configuring click events

    You can select one of the following events: Open app, Open URL, or Open specific app interface.

    Open app

    If you choose Open app, the onNotificationMessageClicked method of Mi will be called back, and the app itself can process app opening in this method.

    Open URL

    You need to select Open URL in Step 2: add a certificate and enter a URL that starts with either http:// or https://, such as https://intl.cloud.tencent.com/document/product/269?from_cn_redirect=1.

    Open specific app interface

    1. In manifest, configure the intent-filter of the Activity to be opened. See the sample code below. You can refer to AndroidManifest.xml of the demo:

      <activity
          android:name="com.tencent.qcloud.tim.demo.chat.ChatActivity"
          android:launchMode="singleTask"
          android:screenOrientation="portrait"
          android:windowSoftInputMode="adjustResize|stateHidden">
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <data
                  android:host="com.tencent.qcloud.tim"
                  android:path="/detail"
                  android:scheme="pushscheme" />
          </intent-filter>
      </activity>
    2. Obtain the intent URL, as shown below:

      Intent intent = new Intent(this, ChatActivity.class);
      intent.setData(Uri.parse("pushscheme://com.tencent.qcloud.tim/detail"));
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      String intentUri = intent.toUri(Intent.URI_INTENT_SCHEME);
      Log.i(TAG, "intentUri = " + intentUri);
      
      // Print results
      intent://com.tencent.qcloud.tim/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.chat.ChatActivity;end
    3. Select Open specific app interface in Step 2: add a certificate and enter the result above.

    Custom content pass through

    Select Open app or Open specific app interface when configuring Click event in Step 2: add a certificate to support custom content pass through.

    Step 1: custom content configuration (sender)
    Set the custom content for the notification bar message before sending the message.

    • Below is a simple example on the Android platform. You can also refer to the corresponding logic in the sendMessage() method in the ChatManagerKit.java class in the TUIKit:

      JSONObject jsonObject = new JSONObject();
      try {
          jsonObject.put("extKey", "ext content");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      String extContent = jsonObject.toString();
      
      V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
      v2TIMOfflinePushInfo.setExt(extContent.getBytes());
      V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, userID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false,  v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
          @Override
          public void onError(int code, String desc) {}
          @Override
          public void onSuccess(V2TIMMessage v2TIMMessage) {}
          @Override
          public void onProgress(int progress) {}
      });
    • For information on configurations for the IM server, refer to the OfflinePushInfo Format Example.

    Step 2: custom content configuration (receiver)

    • If you selected Open app in Step 2: add a certificate, clicking the notification bar message triggers the onNotificationMessageClicked(Context context, MiPushMessage miPushMessage) callback. The custom content can be obtained from miPushMessage. You can refer to the parsing implementation in XiaomiMsgReceiver.java.

      Map extra = miPushMessage.getExtra();
      String extContent = extra.get("ext");
    • If you selected Open specific app interface in Step 2: add a certificate, MiPushMessage, which is the object that encapsulates the message, is passed to the client through Intent. The client then obtains the custom content from Activity. You can refer to the implementation of the parseOfflineMessage(Intent intent) method in the OfflineMessageDispatcher.java class.

        Bundle bundle = getIntent().getExtras(); 
        MiPushMessage miPushMessage = (MiPushMessage)bundle.getSerializable(PushMessageHelper.KEY_MESSAGE); 
        Map extra = miPushMessage.getExtra(); 
        String extContent = extra.get("ext");

    Huawei Push

    Configuring the push certificate

    1. Access the official website of the Huawei Developers Alliance, register an account, and pass the developer verification. Log in to the console of the Huawei Developers Alliance, choose App Service > Development Service > PUSH, and create a Huawei push service app. Take note of the Package name, APP ID, and APP SECRET.

    2. Log in to the IM console and click the target app card to go to the basic configuration page of the app. Click Add a certificate under Android push configuration. Use the information you obtained in step 1 to configure the following parameters:

      • Push platform: select Huawei.
      • Package name: the name of the Huawei Push service app.
      • AppID: enter the App ID you got from Huawei Push.
      • AppSecret: enter the APP SECRET you got from Huawei Push.
      • Badge Parameter: enter the full Activity class name of the app entry, which will be used as the Huawei desktop app badge for display. See Huawei Desktop Badge Development Guide.
      • Click event: the event to take place after the notification bar message is clicked. Valid values include Open app, Open URL, and Open specific app interface. For more information, refer to Configuring Click Event.
      • Open app* or Open specific app interface allows custom content pass through.

        Click Save to save the information. Take note of the ID of the certificate. Certificate information takes effect within 10 minutes after you save it.

    Integrating the push SDK

    1. Add the Huawei dependencies: implementation 'com.tencent.tpns:huawei:1.2.1.2-release' and implementation 'com.huawei.hms:push:5.0.2.300'.
    2. Refer to the Integration Guide for Huawei Push and use the Huawei console to test notification messages to ensure that the SDK was integrated properly.
    3. Call the Huawei HmsInstanceId.getToken API to request the unique app identifier Push Token from the server. Push Token is the unique identifier of the current app on the current device. After successful login to the IM SDK, you need to call setOfflinePushConfig to report the certificate ID and Push Token to the IM server.

    After the certificate ID and regId are successfully reported, the IM server sends messages via Huawei Push notifications to the user when the app has been killed but the user has not logged out of IM.

    Configuring click events

    You can select one of the following events: Open app, Open URL, or Open specific app interface.

    Open app

    This is the default event, which opens the app once the notification bar message is clicked.

    Open URL

    You need to select Open URL in Step 2: add a certificate and enter a URL that starts with either http:// or https://, such as https://intl.cloud.tencent.com/document/product/269?from_cn_redirect=1.

    Open specific app interface

    1. In manifest, configure the intent-filter of the Activity to be opened. See the sample code below. You can refer to AndroidManifest.xml of the demo:

      <activity
          android:name="com.tencent.qcloud.tim.demo.chat.ChatActivity"
          android:launchMode="singleTask"
          android:screenOrientation="portrait"
          android:windowSoftInputMode="adjustResize|stateHidden">
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <data
                  android:host="com.tencent.qcloud.tim"
                  android:path="/detail"
                  android:scheme="pushscheme" />
          </intent-filter>
      </activity>
    2. Obtain the intent URL, as shown below:

      Intent intent = new Intent(this, ChatActivity.class);
      intent.setData(Uri.parse("pushscheme://com.tencent.qcloud.tim/detail"));
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      String intentUri = intent.toUri(Intent.URI_INTENT_SCHEME);
      Log.i(TAG, "intentUri = " + intentUri);
      
      // Print results
      intent://com.tencent.qcloud.tim/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.chat.ChatActivity;end
    3. Select Open specific app interface in Step 2: add a certificate and enter the result above.

    Custom content pass through

    Note:

    Due to the compatibility issues of Huawei Push, the pass-through content can only be received on some EUI10+ devices.

    Step 1: custom content configuration (sender)
    Set the custom content for the notification bar message before sending the message.

    • Below is a simple example on the Android platform. You can also refer to the corresponding logic in the sendMessage() method in the ChatManagerKit.java class in the TUIKit:

      JSONObject jsonObject = new JSONObject();
      try {
          jsonObject.put("extKey", "ext content");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      String extContent = jsonObject.toString();
      
      V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
      v2TIMOfflinePushInfo.setExt(extContent.getBytes());
      V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, userID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false,  v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
          @Override
          public void onError(int code, String desc) {}
          @Override
          public void onSuccess(V2TIMMessage v2TIMMessage) {}
          @Override
          public void onProgress(int progress) {}
      });
    • For information on configurations for the IM server, refer to the OfflinePushInfo Format Example.

    Step 2: custom content configuration (receiver)

    • If you selected Open app or Open specific app interface in Step 1: add a certificate, the client can obtain the custom content from Activity when the notification bar message is clicked. You can refer to the parseOfflineMessage(Intent intent) implementation method in the OfflineMessageDispatcher.java class.
    Bundle bundle = getIntent().getExtras();
    String value = bundle.getString("ext"); 

    OPPO Push

    Configuring the push certificate

    1. Refer to How to enable OPPO Push for instructions on how to enable OPPO Push. Go to OPPO push platform > Configuration Management > App Configuration to view detailed app information. Take note of AppId, AppKey, AppSecret, and MasterSecret.

    2. The official OPPO documentation states that ChannelIDs are required for push messages on OPPO Android 8.0 and above. Therefore, create a ChannelID for your app. Below is a sample code that creates a ChannelID called tuikit:

      public void createNotificationChannel(Context context) {
                      // Create the NotificationChannel, but only on API 26+ because
                      // the NotificationChannel class is new and not in the support library
                      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                              CharSequence name = "oppotest";
                              String description = "this is opptest";
                              int importance = NotificationManager.IMPORTANCE_DEFAULT;
                              NotificationChannel channel = new NotificationChannel("tuikit", name, importance);
                              channel.setDescription(description);
                              // Register the channel with the system; you can't change the importance
                              // or other notification behaviors after this
                              NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
                              notificationManager.createNotificationChannel(channel);
                      }
              }

    3. Log in to the IM console and click the target app card to go to the basic configuration page of the app. Click Add a certificate under Android push configuration. Use the information you obtained in step 1 to configure the following parameters:

      • Push platform: select OPPO.
      • AppKey: enter the AppKey you got from OPPO PUSH.
      • AppID: enter the AppID you got from OPPO PUSH.
      • MasterSecret: enter the MasterSecret you got from OPPO PUSH.
      • ChannelID: enter the ChannelID generated in Step 2.
      • Click event: the event to take place after the notification bar message is clicked. Valid values include Open app, Open URL, and Open specific app interface. For more information, refer to Configuring Click Event.
      • Open app* or Open specific app interface allows custom content pass through.

        Click OK to save the information. Take note of the ID of the certificate. Certificate information takes effect within 10 minutes after you save it.

    Integrating the push SDK

    1. Add the OPPO dependency: implementation 'com.tencent.tpns:oppo:1.2.1.2-release'.
    2. Refer to the OPPO PUSH SDK API Documentation and use the OPPO console to test notification messages to ensure that the SDK was integrated properly.
    3. Call HeytapPushManager.register(…) in the OPPO SDK to initialize the Opush service.
      After successful registration, you can obtain regId in the onRegister callback method of ICallBackResultService. regId is the unique identifier of the current app on the current device. After successful login to the IM SDK, you need to call setOfflinePushConfig to report the certificate ID and regId to the IM server.

    After the certificate ID and regId are successfully reported, the IM server sends messages via OPPO Push notifications to the user when the app has been killed but the user has not logged out of IM.

    Configuring click events

    You can select one of the following events: Open app, Open URL, or Open specific app interface.

    Open app

    This is the default event, which opens the app once the notification bar message is clicked.

    Open URL

    You need to select Open URL in Step 2 and enter a URL that starts with either http or https, such as https://intl.cloud.tencent.com/document/product/269?from_cn_redirect=1.

    Open specific app interface

    These are the ways you can open a specific app interface:

    Activity (recommended)
    This is rather simple. Enter the whole name of an Activity, such as com.tencent.qcloud.tim.demo.SplashActivity

    Intent action

    1. In AndroidManifest, set the following configuration in the Activity to be opened and add category without data. You can refer to AndroidManifest.xml of the demo:
    <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    1. Enter android.intent.action.VIEW in the console.

    Custom content pass through

    Select Open app or Open specific app interface when configuring Click event in Step 2: add a certificate to support custom content pass through.

    Step 1: custom content configuration (sender)
    Set the custom content for the notification bar message before sending the message.

    • Below is a simple example on the Android platform. You can also refer to the corresponding logic in the sendMessage() method in the ChatManagerKit.java class in the TUIKit:

      JSONObject jsonObject = new JSONObject();
      try {
          jsonObject.put("extKey", "ext content");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      String extContent = jsonObject.toString();
      
      V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
      v2TIMOfflinePushInfo.setExt(extContent.getBytes());
      V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, userID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false,  v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
          @Override
          public void onError(int code, String desc) {}
          @Override
          public void onSuccess(V2TIMMessage v2TIMMessage) {}
          @Override
          public void onProgress(int progress) {}
      });
    • For information on configurations for the IM server, refer to the OfflinePushInfo Format Example.

    Step 2: custom content configuration (receiver)
    When the notification bar message is clicked, the client can obtain the custom content from the launched Activity. You can refer to the parseOfflineMessage(Intent intent) implementation method in the OfflineMessageDispatcher.java class.

    Bundle bundle = intent.getExtras();
        Set<String> set = bundle.keySet();
        if (set != null) {
                for (String key : set) {
                    // key and value correspond to extKey and ext content set in Step 1.
                        String value = bundle.getString(key);
                        Log.i("oppo push custom data", "key = " + key + ":value = " + value);
                }
        }

    vivo Push

    Configuring the push certificate

    1. Visit the vivo open platform official website and register for an account. Complete developer verification. Log in to the console of the vivo open platform, choose Message Push > Create > Test Push, and create a vivo push service app. Take note of APP ID, APP key, and APP secret.

    2. Log in to the IM console and click the target app card to go to the basic configuration page of the app. Click Add a certificate under Android push configuration. Use the information you obtained in step 1 to configure the following parameters:

      • Push platform: select vivo.
      • AppKey: enter the AppKey you got from vivo Push.
      • AppID: enter the AppID you got from vivo Push.
      • AppSecret: enter the APP secret you got from vivo Push.
      • Click event: the event to take place after the notification bar message is clicked. Valid values include Open app, Open URL, and Open specific app interface. For more information, refer to Configuring Click Event.
      • Open app* or Open specific app interface allows custom content pass through.

        Click OK to save the information. Take note of the ID of the certificate. Certificate information takes effect 10 minutes after you save it.

    Integrating the push SDK

    1. Add vivo dependency: implementation 'com.tencent.tpns:vivo:1.2.1.2-release'.
    2. Refer to the Integration Guide for vivo Push, and use the vivo console to test notification messages to ensure that the SDK was integrated properly.
    3. Call PushClient.getInstance(getApplicationContext()).initialize() to initialize the vivo Push service and call PushClient.getInstance(getApplicationContext()).turnOnPush() to launch push. If this succeeds, you will receive the regId in the onReceiveRegId of the custom BroadcastReceiver. regId is the unique identifier of the current app on the current device. After successful login to the IM SDK, you need to call setOfflinePushConfig to report the certificate ID and regId to the IM server.

    After the certificate ID and regId are successfully reported, the IM server sends messages via vivo Push notifications to the user when the app has been killed but the user has not logged out of IM.

    Configuring click events

    You can select one of the following events: Open app, Open URL, or Open specific app interface.

    Open app

    This is the default event, which opens the app once the notification bar message is clicked.

    Open URL

    You need to select Open URL in Step 2: add a certificate and enter a URL that starts with either http:// or https://, such as https://intl.cloud.tencent.com/document/product/269?from_cn_redirect=1.

    Open specific app interface

    1. In manifest, configure the intent-filter of the Activity to be opened. See the sample code below. You can refer to AndroidManifest.xml of the demo:

      <activity
          android:name="com.tencent.qcloud.tim.demo.chat.ChatActivity"
          android:launchMode="singleTask"
          android:screenOrientation="portrait"
          android:windowSoftInputMode="adjustResize|stateHidden">
          <intent-filter>
              <action android:name="android.intent.action.VIEW" />
              <data
                  android:host="com.tencent.qcloud.tim"
                  android:path="/detail"
                  android:scheme="pushscheme" />
          </intent-filter>
      </activity>
    2. Obtain the intent URL, as shown below:

      Intent intent = new Intent(this, ChatActivity.class);
      intent.setData(Uri.parse("pushscheme://com.tencent.qcloud.tim/detail"));
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      String intentUri = intent.toUri(Intent.URI_INTENT_SCHEME);
      Log.i(TAG, "intentUri = " + intentUri);
      
      // Print results
      intent://com.tencent.qcloud.tim/detail#Intent;scheme=pushscheme;launchFlags=0x4000000;component=com.tencent.qcloud.tim.tuikit/com.tencent.qcloud.tim.demo.chat.ChatActivity;end
    3. Select Open specific app interface in Step 2: add a certificate and enter the result above.

    Custom content pass through

    Select Open app or Open specific app interface when configuring Click event in Step 2: add a certificate to support custom content pass through.

    Step 1: custom content configuration (sender)
    Set the custom content for the notification bar message before sending the message.

    • Below is a simple example on the Android platform. You can also refer to the corresponding logic in the sendMessage() method in the ChatManagerKit.java class in the TUIKit:

      JSONObject jsonObject = new JSONObject();
      try {
          jsonObject.put("extKey", "ext content");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      String extContent = jsonObject.toString();
      
      V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
      v2TIMOfflinePushInfo.setExt(extContent.getBytes());
      V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, userID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false,  v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
          @Override
          public void onError(int code, String desc) {}
          @Override
          public void onSuccess(V2TIMMessage v2TIMMessage) {}
          @Override
          public void onProgress(int progress) {}
      });
    • For information on configurations for the IM server, refer to the OfflinePushInfo Format Example.

    Step 2: custom content configuration (receiver)
    When the notification bar message is clicked, the onNotificationMessageClicked(Context context, UPSNotificationMessage upsNotificationMessage) callback of the vivo Push SDK is triggered. The custom content can be obtained from upsNotificationMessage. You can refer to the parsing implementation in VIVOPushMessageReceiverImpl.java.

    Map<String, String> paramMap = upsNotificationMessage.getParams();
    String extContent = paramMap.get("ext");

    Meizu Push

    Configuring the push certificate

    1. Access the Meizu open platform website to register an account and pass the developer verification. Log in to the Meizu console, choose Development Service > Flyme Push and create a Meizu push service app. Take note of the app package name, App ID, and App Secret.

    2. Log in to the IM console and click the target app card to go to the basic configuration page of the app. Click Add a certificate under Android push configuration. Use the information you obtained in step 1 to configure the following parameters:

      • Push Platform: choose Meizu.
      • App Package Name: enter the App package name of the Meizu push service app.
      • AppID: enter the App ID of the Meizu push service app.
      • AppSecret: enter the App Secret of the Meizu push service app.
      • Click event: the event to take place after the notification bar message is clicked. Valid values include Open app, Open URL, and Open specific app interface. For more information, refer to Configuring Click Event.
      • Open app* or Open specific app interface allows custom content pass through.

        Click OK to save the information. Take note of the ID of the certificate. Certificate information takes effect within 10 minutes after you save it.

    Integrating the push SDK

    1. Add Meizu dependency: implementation 'com.tencent.tpns:meizu:1.2.1.2-release'.
    2. Refer to Meizu Push Integration, and use the Meizu console to test notification messages to ensure that the SDK was integrated properly.
    3. Call PushManager.register to initialize the Meizu Push service. After successful registration, you will receive the registration result in onRegisterStatus of the custom BroadcastReceiver. registerStatus.getPushId()is the unique identifier of the current app on the current device. After successful login to the IM SDK, you need to call setOfflinePushConfig to report the certificate ID and PushId to the IM server.

    After the certificate ID and regId are successfully reported, the IM server sends messages via Meizu Push notifications to the user when the app has been killed but the user has not logged out of IM.

    Configuring click events

    You can select one of the following events: Open app, Open URL, or Open specific app interface.

    Open app

    This is the default event, which opens the App once the notification bar message is clicked.

    Open URL

    You need to select Open URL in Step 2: add a certificate and enter a URL that starts with either http:// or https://, such as https://intl.cloud.tencent.com/document/product/269?from_cn_redirect=1.

    Open specific app interface

    When adding a certificate, you need to choose Open specific app interface and enter the complete class name of the Activity to be opened, for example, com.tencent.qcloud.tim.demo.chat.ChatActivity.

    Custom content pass through

    Select Open app or Open specific app interface when configuring Click event in Step 2: add a certificate to support custom content pass through.

    Step 1: custom content configuration (sender)
    Set the custom content for the notification bar message before sending the message.

    • Below is a simple example on the Android platform. You can also refer to the corresponding logic in the sendMessage() method in the ChatManagerKit.java class in the TUIKit:

      JSONObject jsonObject = new JSONObject();
      try {
          jsonObject.put("extKey", "ext content");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      String extContent = jsonObject.toString();
      
      V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
      v2TIMOfflinePushInfo.setExt(extContent.getBytes());
      V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, userID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false,  v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
          @Override
          public void onError(int code, String desc) {}
          @Override
          public void onSuccess(V2TIMMessage v2TIMMessage) {}
          @Override
          public void onProgress(int progress) {}
      });
    • For information on configurations for the IM server, refer to the OfflinePushInfo Format Example.

    Step 2: custom content configuration (receiver)

    Clicking a notification bar message triggers a callback of onNotificationClicked(Context context, MzPushMessage mzPushMessage), which is part of the Meizu Push SDK. The custom content can be obtained from the value of mzPushMessage .

    String extContent = mzPushMessage.getSelfDefineContentString();

    Alternatively, the client can obtain the custom content from the opened Activity. You can refer to the parseOfflineMessage(Intent intent) implementation method in the OfflineMessageDispatcher.java class.

    Bundle bundle = getIntent().getExtras();
    String extContent = bundle.getString("ext"); 

    Google FCM Push

    Integrating the SDK

    1. Register with Firebase Cloud Messaging and create an app.
    2. Log in to the Firebase console and click your app card to go to the app configuration page. Click on the right side of Project Overview, choose Project Settings > Service Account, and click Generate New Private Key to generate a new private key file.
    3. Log in to the Tencent Cloud IM console and click the target app card to go to the basic configuration page of the app. Click Add a certificate under Android push configuration. Upload the private key file obtained in Step 2.
    4. Click OK to save the information. Take note of the ID of the certificate. Certificate information takes effect within 10 minutes after you save it.

    Integrating the push SDK

    1. Add the FCM dependency: implementation 'com.google.firebase:firebase-messaging:20.2.3'.
    2. Refer to Firebase Cloud Messaging to set up Firebase. Refer to the FCM Testing Guide to test notification messages to ensure that FCM was integrated properly.
    3. After calling FirebaseInstanceId.getInstance().getInstanceId(), you can obtain the token in the callback. The token is the unique identifier of the current app. After successful login to the IM SDK, you need to call setOfflinePushConfig to report the certificate ID and token to the IM server.

    After the certificate ID and regId are successfully reported, the IM server sends messages via FCM Push notifications to the user when the app has been killed but the user has not logged out of IM.

    Custom content pass through

    Step 1: custom content configuration (sender)
    Set the custom content for the notification bar message before sending the message.

    • Below is a simple example on the Android platform. You can also refer to the corresponding logic in the sendMessage() method in the ChatManagerKit.java class in the TUIKit:

      JSONObject jsonObject = new JSONObject();
      try {
          jsonObject.put("extKey", "ext content");
      } catch (JSONException e) {
          e.printStackTrace();
      }
      String extContent = jsonObject.toString();
      
      V2TIMOfflinePushInfo v2TIMOfflinePushInfo = new V2TIMOfflinePushInfo();
      v2TIMOfflinePushInfo.setExt(extContent.getBytes());
      V2TIMManager.getMessageManager().sendMessage(v2TIMMessage, userID, null, V2TIMMessage.V2TIM_PRIORITY_DEFAULT, false,  v2TIMOfflinePushInfo, new V2TIMSendCallback<V2TIMMessage>() {
          @Override
          public void onError(int code, String desc) {}
          @Override
          public void onSuccess(V2TIMMessage v2TIMMessage) {}
          @Override
          public void onProgress(int progress) {}
      });
    • For information on configurations for the IM server, refer to the OfflinePushInfo Format Example.

    Step 2: custom content configuration (receiver)
    When the notification bar message is clicked, the client can obtain the custom content from the corresponding Activity. You can refer to the parseOfflineMessage(Intent intent) implementation method in the OfflineMessageDispatcher.java class.

    Bundle bundle = getIntent().getExtras();
    String value = bundle.getString("ext"); 

    Setting Custom iOS Push Alert Sound

    When calling sendMessage to send messages, use the setIOSSound API in V2TIMOfflinePushInfo to set the sound for push notifications on iOS devices.

    Setting Custom Display for Offline Push

    When calling sendMessage to send messages, use setTitle and setDesc in V2TIMOfflinePushInfo to set the title and content of notification bar messages respectively.

    FAQ

    How to set a custom sound for push notifications on Android phones?

    Currently, most vendors do not support setting a custom sound for push notifications, therefore it is not supported by the IM SDK.

    Why do OPPO mobile phones fail to receive offline push messages?

    This generally occurs for the following reasons:

    • According to requirements on the official website of OPPO Push, ChannelID must be configured on OPPO mobile phones that run Android 8.0 or later versions. Otherwise, push messages cannot be displayed. For the configuration method, see OPPO Push configuration.
    • The custom content in the message for pass-through offline push is not in the JSON format. As a result, OPPO mobile phones do not receive the push message.

    Why doesn’t offline push work for custom messages?

    The offline push for custom messages is different from that for ordinary messages. As we cannot parse the content of custom messages, the push content cannot be determined. Therefore, by default, custom messages are not pushed offline. If you need offline push for custom messages, you need to set the desc field in offlinePushInfo during sendMessage, and the desc information will be displayed by default during push.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help