SDK API
Last updated:2022-12-30

SDK API

MTCorePrivatesApi

  • Mainly used for information configuration
  • All methods need to be called in the main process. Please do not put it in the child process by judging the process before calling the method, otherwise, unexpected errors will occur

configHeartbeatInterval

  • You need to call this method in the Application.onCreate() method
  • Please call before init
/** * Set heartbeat interval * * You need to call in the Application.onCreate() method * * @param context is not empty * @param heartbeatInterval The time unit is milliseconds. It must be greater than 0. The default value is 4 minutes and 50 seconds. */ public static void configHeartbeatInterval(Context context, long heartbeatInterval)
              /**
     * Set heartbeat interval
     *
     * You need to call in the Application.onCreate() method
     *
     * @param context is not empty
     * @param heartbeatInterval The time unit is milliseconds. It must be greater than 0. The default value is 4 minutes and 50 seconds.
     */
    public static void configHeartbeatInterval(Context context, long heartbeatInterval)

        
This code block in the floating window

The code example is as follows

  • Demonstrate setting the heartbeat interval to 3 minutes
MTCorePrivatesApi.configHeartbeatInterval(this,3 * 60 * 1000);
          MTCorePrivatesApi.configHeartbeatInterval(this,3 * 60 * 1000);

        
This code block in the floating window

configConnectRetryCount

  • You need to call this method in the Application.onCreate() method
  • Please call before init
/** *Set the number of long connection retries * * You need to call in the Application.onCreate() method * * @param context is not empty * @param connectRetryCount Number of retries. The default value is 3. At least 3 retries */ public static void configConnectRetryCount(Context context, int connectRetryCount)
              /**
     *Set the number of long connection retries
     *
     * You need to call in the Application.onCreate() method
     *
     * @param context is not empty
     * @param connectRetryCount Number of retries. The default value is 3. At least 3 retries
     */
    public static void configConnectRetryCount(Context context, int connectRetryCount)

        
This code block in the floating window

The code example is as follows

Demonstrate setting reconnection times to 10

MTCorePrivatesApi.configConnectRetryCount(this,10);
          MTCorePrivatesApi.configConnectRetryCount(this,10);

        
This code block in the floating window

configDebugMode

  • It needs to be called in the Application.onCreate() method
  • Please call before init
  • Private cloud Engagelab log format, search for "ENGAGELAB-PRIVATES"
  • Private cloud Engagelab will print logs in the main process and sub process respectively
/** * Set whether to debug mode, which will print more detailed logs * * You need to call in the Application.onCreate() method * * @Param context is not empty * @param enable Whether to debug mode, true is the debug mode, false is not */ public static void configDebugMode(Context context, boolean enable)
              /**
     * Set whether to debug mode, which will print more detailed logs
     *
     * You need to call in the Application.onCreate() method
     * 
     * @Param context is not empty
     * @param enable Whether to debug mode, true is the debug mode, false is not
     */
    public static void configDebugMode(Context context, boolean enable)

        
This code block in the floating window

The code example is as follows

  • The sdk works in two processes, the main process and the sub process. The sub process name is the process attribute name of the MTCommonService sub class service
  • The log tag of the private cloud sdk is "ENGAGELAB-PRIVATES"
  • The logs of udp/tcp/http related operations are in the child process
  • Therefore, if the message cannot be pushed, please turn on the debugging mode first, and then go to the sub process to obtain the log with the tag of "ENGAGELAB-PRIVATES" for technical support analysis
// It is recommended to set it to true when the application is not online for easy integration MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // It is recommended that the application be set to false after going online MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), false);
                  // It is recommended to set it to true when the application is not online for easy integration
        MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true);
        
        // It is recommended that the application be set to false after going online
        MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), false);

        
This code block in the floating window

configSM4

  • It needs to be called in the Application. onCreate() method
  • Please call before init
/** * Configure to use national security encryption * * @param context is not empty */ public static void configSM4(Context context)
              /**
     * Configure to use national security encryption
     *
     * @param context is not empty
     */
    public static void configSM4(Context context)

        
This code block in the floating window

The sample code is as follows

// Enable national security encryption, and use the default encryption method if not called MTCorePrivatesApi.configSM4(context.getApplicationContext());
              // Enable national security encryption, and use the default encryption method if not called
    MTCorePrivatesApi.configSM4(context.getApplicationContext());

        
This code block in the floating window

getUserId

When the return value is null, you should check whether the environment is configured and whether initialization methoid is called If the configuration is correct, it may still be in the process of connection. You can obtain it when onConnectStatus returns true

/** * Get the userId of the current device, the unique ID of the Engagelab private cloud, which can be the same as push * * @param context is not empty * @return userId */ public static String getUserId(Context context)
              /**
     * Get the userId of the current device, the unique ID of the Engagelab private cloud, which can be the same as push
     *
     * @param context is not empty
     * @return userId
     */
    public static String getUserId(Context context)

        
This code block in the floating window

The code example is as follows

String userId = MTCorePrivatesApi.getUserId(context);
                  String userId = MTCorePrivatesApi.getUserId(context);

        
This code block in the floating window

getRegistrationId

  • When the return value is null, you should check whether the environment is configured and whether initialization is called.
  • If the configuration is correct, it may still be in the process of connection. You can obtain it when onConnectStatus returns true.
/** * Get the registrationId of the current device, the unique ID of the Engagelab private cloud, which can be the same as push * * @param context is not empty * @return registrationId */ public static String getRegistrationId(Context context)
              /**
     * Get the registrationId of the current device, the unique ID of the Engagelab private cloud, which can be the same as push
     *
     * @param context is not empty
     * @return registrationId
     */
    public static String getRegistrationId(Context context)

        
This code block in the floating window

The code example is as follows:

String registrationId = MTPushPrivatesApi.getRegistrationId(context);
          String registrationId = MTPushPrivatesApi.getRegistrationId(context);

        
This code block in the floating window

MTPushPrivatesApi

  • Mainly used for push function
  • All methods need to be called in the main process. Please do not put it in the child process by judging the process before calling the method, otherwise, unexpected errors will occur

configOldPushVersion

  • The background server has not upgraded the version tag: V3.5.4-newportal-20210823-gamma.57. The front end must call this method, or it will notify you that there is a problem when clicking notification jump.
  • Call in the Application.onCreate() method
  • Please call before init
/** * Configure the push version as 3.9. X * * @param context is not empty */ public static void configOldPushVersion(Context context)
              /**
     * Configure the push version as 3.9. X
     *
     * @param context is not empty
     */
    public static void configOldPushVersion(Context context)

        
This code block in the floating window

The code example is as follows:

public class ExampleApplication extends Application { @Override public void onCreate() { // Turn on debug mode MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // Click to jump using the old notification MTPushPrivatesApi.configOldPushVersion(context.getApplicationContext()); // initialization MTPushPrivatesApi.init(context.getApplicationContext()); } }
          public class ExampleApplication extends Application {

    @Override
    public void onCreate() {
        // Turn on debug mode    
            MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true);
            // Click to jump using the old notification
            MTPushPrivatesApi.configOldPushVersion(context.getApplicationContext());
            // initialization
                MTPushPrivatesApi.init(context.getApplicationContext());   
    }
}

        
This code block in the floating window

init

  • It is recommended to call in the Application.onCreate() method
/** * MTPush initialization * * It is recommended to call in the Application.onCreate() method * * @param context is not empty, please use the applicationContext object */ public static void init(Context context)
              /**
     * MTPush initialization
     *
     * It is recommended to call in the Application.onCreate() method
     * 
     * @param context is not empty, please use the applicationContext object
     */
    public static void init(Context context)

        
This code block in the floating window

The code example is as follows:

public class ExampleApplication extends Application { @Override public void onCreate() { // Turn on debug mode MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // initialization MTPushPrivatesApi.init(context.getApplicationContext()); } }
          public class ExampleApplication extends Application {

    @Override
    public void onCreate() {
        // Turn on debug mode    
            MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true);
            // initialization
                MTPushPrivatesApi.init(context.getApplicationContext());   
    }
}

        
This code block in the floating window

goToAppNotificationSettings

  • After starting the sdk, you can decide whether to call this interface according to the onNotificationStatus callback result
/** * Go to the notification switch setting page * * @param context not empty */ public static void goToAppNotificationSettings(Context context)
              /**
     * Go to the notification switch setting page
     *
     * @param context not empty
     */
    public static void goToAppNotificationSettings(Context context)

        
This code block in the floating window

The code example is as follows:

// Go to the notification switch setting page, and the customer needs to manually turn on the notification switch MTPushPrivatesApi.goToAppNotificationSettings(this); // After inheriting MTCommonReceiver, copy the onNotificationStatus method to obtain the status of the notification switch. If enable is true, it indicates that it has been successfully enabled @Override public void onNotificationStatus(Context context, boolean enable) { if(enable){ // The notification switch is set to ON } }
              // Go to the notification switch setting page, and the customer needs to manually turn on the notification switch
    MTPushPrivatesApi.goToAppNotificationSettings(this);
    
    // After inheriting MTCommonReceiver, copy the onNotificationStatus method to obtain the status of the notification switch. If enable is true, it indicates that it has been successfully enabled
    @Override
    public void onNotificationStatus(Context context, boolean enable) {
                if(enable){
                        // The notification switch is set to ON
                }	    
    }

        
This code block in the floating window

turnOnPush

  • It is generally used to enable push notification switch after calling turnOffPush
  • Repeated calls will only take effect once. If they are already enabled, they will not take effect again
  • If there is no problem with the environment,onConnectStatus will call back the results
  • Currently supported channels::Engagelab/Huawei/Xiaomi/Meizu/oppo/vivo
/** * Enable Push, and the status of the persistent storage switch is true. The default is true * * @param context not empty */ public static void turnOnPush(Context context)
              /**
     * Enable Push, and the status of the persistent storage switch is true. The default is true
     * 
     * @param context not empty
     */
    public static void turnOnPush(Context context)

        
This code block in the floating window

The code example is as follows:

// Push is enabled by default MTPushPrivatesApi.turnOnPush(context); // After inheriting MTCommonReceiver, copy the onConnectStatus method to obtain the connection status of the long connection. If enable is true, it indicates that it has been successfully enabled @Override public void onConnectStatus(Context context, boolean enable){ if(enable){ // Successfully enabled push } }
                  // Push is enabled by default
        MTPushPrivatesApi.turnOnPush(context);
        
        // After inheriting MTCommonReceiver, copy the onConnectStatus method to obtain the connection status of the long connection. If enable is true, it indicates that it has been successfully enabled
        @Override
        public void onConnectStatus(Context context, boolean enable){
                if(enable){
                        // Successfully enabled push
                }				
        }

        
This code block in the floating window

turnOffPush

  • It is generally used to turn off push
  • After closing push notification switch, calling init will not open push
  • Repeated calls will only take effect once
  • If there is no problem with the environment,onConnectStatus will call back the results
  • Currently supported channels::Engagelab/Huawei/Xiaomi/Meizu/oppo/vivo
/** * Turn off push, and the persistent storage switch status is false. The default is true * * @param context not empty */ public static void turnOffPush(Context context)
              /**
     * Turn off push, and the persistent storage switch status is false. The default is true
     *
     * @param context not empty
     */
    public static void turnOffPush(Context context)

        
This code block in the floating window

The code example is as follows:

// Turn off push. You need to call turnOnPush again to turn on push MTPushPrivatesApi.turnOffPush(context); // After inheriting MTCommonReceiver, copy the onConnectStatus method to obtain the long connection status. If enable is false, it indicates that it has been closed successfully @Override public void onConnectStatus(Context context, boolean enable){ if(!enable){ // Successfully closed push } }
                  // Turn off push. You need to call turnOnPush again to turn on push
        MTPushPrivatesApi.turnOffPush(context);
        
        // After inheriting MTCommonReceiver, copy the onConnectStatus method to obtain the long connection status. If enable is false, it indicates that it has been closed successfully
        @Override
        public void onConnectStatus(Context context, boolean enable){
                if(!enable){
                        // Successfully closed push
                }
        }

        
This code block in the floating window

setNotificationShowTime

  • init first, or the call will fail
  • Currently supported channels:Engagelab/Google channel when the application is in the foreground (displayed by Engagelab)
/** * Set the display time of the notice. It is displayed at any time by default * * @param context not empty * @param beginHour Allow notification of the start time of the display (24-hour format, ranging from 0 to 23) * @param endHour It is allowed to notify the end time of display (24-hour format, ranging from 0 to 23). beginHour cannot be greater than or equal to endHour * @param weekDays An array of days (7-day system, ranging from 1 to 7) that allows notifications to be displayed. An empty array means that notifications will not be displayed at any time */ public static void setNotificationShowTime(Context context, int beginHour, int endHour, int... weekDays)
              /**
     * Set the display time of the notice. It is displayed at any time by default
     *
     * @param context   not empty
     * @param beginHour Allow notification of the start time of the display (24-hour format, ranging from 0 to 23)
     * @param endHour   It is allowed to notify the end time of display (24-hour format, ranging from 0 to 23). beginHour cannot be greater than or equal to endHour
     * @param weekDays  An array of days (7-day system, ranging from 1 to 7) that allows notifications to be displayed. An empty array means that notifications will not be displayed at any time
     */
    public static void setNotificationShowTime(Context context, int beginHour, int endHour, int... weekDays)

        
This code block in the floating window

The code example is as follows:

// Set the display time of the notice to be 9:00 a.m. to 9:00 p.m. on 1/3/5/7 every week MTPushPrivatesApi.setNotificationShowTime(context, 9, 21, 1,3,5,7);
              // Set the display time of the notice to be 9:00 a.m. to 9:00 p.m. on 1/3/5/7 every week
    MTPushPrivatesApi.setNotificationShowTime(context, 9, 21, 1,3,5,7);

        
This code block in the floating window

resetNotificationShowTime

  • init first, or the call will fail
  • Currently supported channels:Engagelab/Google channel when the application is in the foreground (displayed by Engagelab)
/** * Reset the display time of the notice, and display at any time by default * * @param context not empty */ public static void resetNotificationShowTime(Context context)
              /**
     * Reset the display time of the notice, and display at any time by default
     *
     * @param context not empty
     */
    public static void resetNotificationShowTime(Context context)

        
This code block in the floating window

The code example is as follows:

// Reset the display time of the notice, and display at any time by default MTPushPrivatesApi.resetNotificationShowTime(context);
              // Reset the display time of the notice, and display at any time by default
    MTPushPrivatesApi.resetNotificationShowTime(context);

        
This code block in the floating window

setNotificationSilenceTime

  • init first, or the call will fail
  • Currently supported channels:Engagelab/Google channel when the application is in the foreground (displayed by Engagelab)
/** * Set the notification silence time. By default, no silence occurs at any time * * @param context not empty * @param beginHour The start time of the allowed notification silence, in hours (24-hour format, ranging from 0 to 23) * @param beginMinute The start time of the allowed notification silence, in minutes (60 minute format, ranging from 0 to 59) * @param endHour The end time of the allowed notification silence, in hours (24-hour format, ranging from 0 to 23) * @param endMinute The end time allowed for notification silence, in minutes (60 minute format, ranging from 0 to 59) */ public static void setNotificationSilenceTime(Context context, int beginHour, int beginMinute, int endHour, int endMinute)
              /**
     * Set the notification silence time. By default, no silence occurs at any time
     *
     * @param context     not empty
     * @param beginHour   The start time of the allowed notification silence, in hours (24-hour format, ranging from 0 to 23)
     * @param beginMinute The start time of the allowed notification silence, in minutes (60 minute format, ranging from 0 to 59)
     * @param endHour     The end time of the allowed notification silence, in hours (24-hour format, ranging from 0 to 23)
     * @param endMinute   The end time allowed for notification silence, in minutes (60 minute format, ranging from 0 to 59)
     */
    public static void setNotificationSilenceTime(Context context, int beginHour, int beginMinute, int endHour, int endMinute)

        
This code block in the floating window

The code example is as follows:

// Set the notification silence time from 9:30 p.m. to 9:30 a.m MTPushPrivatesApi.setNotificationSilenceTime(context, 21, 30, 9, 30);
              // Set the notification silence time from 9:30 p.m. to 9:30 a.m
    MTPushPrivatesApi.setNotificationSilenceTime(context, 21, 30, 9, 30);

        
This code block in the floating window

resetNotificationSilenceTime

  • init first, or the call will fail
  • Currently supported channels:Engagelab/Google channel when the application is in the foreground (displayed by Engagelab)
/** * Reset the notification silence time. By default, no silence occurs at any time * * @param context not empty */ public static void resetNotificationSilenceTime(Context context)
              /**
     * Reset the notification silence time. By default, no silence occurs at any time
     *
     * @param context not empty
     */
    public static void resetNotificationSilenceTime(Context context)

        
This code block in the floating window

The code example is as follows:

// Reset the notification silence time. By default, no silence occurs at any time MTPushPrivatesApi.resetNotificationSilenceTime(context);
              // Reset the notification silence time. By default, no silence occurs at any time
    MTPushPrivatesApi.resetNotificationSilenceTime(context);

        
This code block in the floating window

setNotificationLayout

  • init first, or the call will fail
  • Currently supported channels:Engagelab
/** * Set the custom notification layout, and use the system notification layout by default * * @param context not empty * @param builderId builder id * @param notificationLayout Objects that customize the notification layout,not empty */ public static void setNotificationLayout(Context context, int builderId, NotificationLayout notificationLayout)
              /**
     * Set the custom notification layout, and use the system notification layout by default
     *
     * @param context            not empty
     * @param builderId          builder id
     * @param notificationLayout Objects that customize the notification layout,not empty
     */
    public static void setNotificationLayout(Context context, int builderId, NotificationLayout notificationLayout)

        
This code block in the floating window

The code example is as follows:

// A constant is defined here, representing the build id private static final int BUILDER_ID = 11; // build notificationLayout NotificationLayout notificationLayout = new NotificationLayout() .setLayoutId(R.layout.custom_notification_layout) // layout_id .setIconViewId(R.id.iv_notification_icon) // view_id .setIconResourceId(R.drawable.mtpush_notification_icon) // source_id .setTitleViewId(R.id.tv_notification_title) // view_id .setContentViewId(R.id.tv_notification_content) // view_id .setTimeViewId(R.id.tv_notification_time); // view_id // Set the build id to BUILDER_ The custom layout of ID, and the builderId is specified as BUILDER when the notification is issued_ ID, you can change the notification layout MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, notificationLayout);
                  // A constant is defined here, representing the build id
        private static final int BUILDER_ID = 11;
        
        // build notificationLayout
    NotificationLayout notificationLayout = new NotificationLayout()
            .setLayoutId(R.layout.custom_notification_layout)        // layout_id
            .setIconViewId(R.id.iv_notification_icon)                // view_id
            .setIconResourceId(R.drawable.mtpush_notification_icon)   // source_id
            .setTitleViewId(R.id.tv_notification_title)              // view_id
            .setContentViewId(R.id.tv_notification_content)          // view_id
            .setTimeViewId(R.id.tv_notification_time);               // view_id
 
    // Set the build id to BUILDER_ The custom layout of ID, and the builderId is specified as BUILDER when the notification is issued_ ID, you can change the notification layout        
    MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, notificationLayout);

        
This code block in the floating window

resetNotificationLayout

  • init first, or the call will fail
  • Currently supported channels:Engagelab
/** * Reset custom notification layout, default to system notification layout * * @param context not empty * @param builderId ID of custom notification layout */ public static void resetNotificationLayout(Context context, int builderId)
              /**
     * Reset custom notification layout, default to system notification layout
     *
     * @param context   not empty
     * @param builderId    ID of custom notification layout
     */
    public static void resetNotificationLayout(Context context, int builderId)

        
This code block in the floating window

The code example is as follows:

// A constant is defined here, representing the build id private static final int BUILDER_ID = 11; // Reset build id to BUILDER_ The custom layout of ID, and the builderId is specified as BUILDER when the notification is issued_ ID, the system default layout will be used MTPushPrivatesApi.resetNotificationLayout(context,BUILDER_ID);
                  // A constant is defined here, representing the build id
        private static final int BUILDER_ID = 11;
        
    // Reset build id to BUILDER_ The custom layout of ID, and the builderId is specified as BUILDER when the notification is issued_ ID, the system default layout will be used
    MTPushPrivatesApi.resetNotificationLayout(context,BUILDER_ID);

        
This code block in the floating window

setNotificationCount

  • init first, or the call will fail
  • Currently supported channels:Engagelab/Google channel when the application is in the foreground (displayed by Engagelab))
/** * Set the number of notifications in the notification bar. The default number is 5 * * @param context not empty * @param count Limit the number of notifications in the notification bar. If the number exceeds the limit, the oldest notification will be removed. It cannot be less than or equal to 0 */ public static void setNotificationCount(Context context, int count)
              /**
     * Set the number of notifications in the notification bar. The default number is 5
     *
     * @param context not empty
     * @param count   Limit the number of notifications in the notification bar. If the number exceeds the limit, the oldest notification will be removed. It cannot be less than or equal to 0
     */
    public static void setNotificationCount(Context context, int count)

        
This code block in the floating window

The code example is as follows:

// Set the number of notifications in the notification bar to 50 MTPushPrivatesApi.setNotificationCount(context,50);
              // Set the number of notifications in the notification bar to 50
    MTPushPrivatesApi.setNotificationCount(context,50);

        
This code block in the floating window

resetNotificationCount

  • init first, or the call will fail
  • Currently supported channels:Engagelab/Google channel when the application is in the foreground (displayed by Engagelab)
/** * Reset the number of notifications in the notification bar. The default number is 5 * * @param context not empty */ public static void resetNotificationCount(Context context)
              /**
     * Reset the number of notifications in the notification bar. The default number is 5
     *
     * @param context not empty
     */
    public static void resetNotificationCount(Context context)

        
This code block in the floating window

The code example is as follows:

// Reset the number of notifications in the notification bar. The default number is 5 MTPushPrivatesApi.resetNotificationCount(context);
              // Reset the number of notifications in the notification bar. The default number is 5
    MTPushPrivatesApi.resetNotificationCount(context);

        
This code block in the floating window

setNotificationBadge

  • init first, or the call will fail
/** * Set the number of application subscripts. The default is 0 (only effective for Huawei/Honour) * * @param context not empty * @param badge Number of applied corner markers */ public static void setNotificationBadge(Context context, int badge)
              /**
     * Set the number of application subscripts. The default is 0 (only effective for Huawei/Honour)
     *
     * @param context not empty
     * @param badge   Number of applied corner markers
     */
    public static void setNotificationBadge(Context context, int badge)

        
This code block in the floating window

The code example is as follows:

// Set the number of applied subscripts to 1 MTPushPrivatesApi.setNotificationBadge(context,1);
              // Set the number of applied subscripts to 1
    MTPushPrivatesApi.setNotificationBadge(context,1);

        
This code block in the floating window

resetNotificationBadge

  • init first, or the call will fail
/** * Set the number of application subscripts. The default is 0 (only effective for Huawei/Honour) * * @param context not empty */ public static void resetNotificationBadge(Context context) {
              /**
     * Set the number of application subscripts. The default is 0 (only effective for Huawei/Honour)
     *
     * @param context not empty
     */
    public static void resetNotificationBadge(Context context) {

        
This code block in the floating window

The code example is as follows:

// Reset the number of applied subscripts. The default is 0 MTPushPrivatesApi.resetNotificationBadge(context);
              // Reset the number of applied subscripts. The default is 0
    MTPushPrivatesApi.resetNotificationBadge(context);

        
This code block in the floating window

showNotification

  • init first, or the call will fail
/** * Display notice * * @param context not empty * @param notificationMessage Notification object built,not empty */ public static void showNotification(Context context, NotificationMessage notificationMessage)
              /**
     * Display notice
     *
     * @param context             not empty
     * @param notificationMessage Notification object built,not empty
     */
    public static void showNotification(Context context, NotificationMessage notificationMessage)

        
This code block in the floating window

The code example is as follows:

// Build a basic notification, where messageId and content are required, otherwise the notification cannot be displayed NotificationMessage notificationMessage = new NotificationMessage() .setMessageId("12345") .setNotificationId(12345) .setTitle("custom_notification_title") .setContent("custom_notification_content"); // Display notice MTPushPrivatesApi.showNotification(context,notificationMessage);
              // Build a basic notification, where messageId and content are required, otherwise the notification cannot be displayed
    NotificationMessage notificationMessage = new NotificationMessage()
            .setMessageId("12345")
            .setNotificationId(12345)
            .setTitle("custom_notification_title")
            .setContent("custom_notification_content");    
    // Display notice
    MTPushPrivatesApi.showNotification(context,notificationMessage);

        
This code block in the floating window

clearNotification

  • init first, or the call will fail
/** * Clear notification of the specified notifyId * * @param context not empty * @param notifyId notice id */ public static void clearNotification(Context context, int notifyId)
              /**
     * Clear notification of the specified notifyId
     *
     * @param context  not empty
     * @param notifyId notice id
     */
    public static void clearNotification(Context context, int notifyId)

        
This code block in the floating window

The code example is as follows:

// Clear notification of the specified notifyId MTPushPrivatesApi.clearNotification(context,12345);
              // Clear notification of the specified notifyId
    MTPushPrivatesApi.clearNotification(context,12345);

        
This code block in the floating window

reportNotificationArrived

  • init first, or the call will fail
  • The manufacturer package of Engagelab is not integrated, but you still need to use Engagelab to statistics the notification delivery rate. Please call this interface
/** * Report the arrival of manufacturer channel notification * * Report via http/https * * @param context not empty * @param messageId Engagelab message id,not empty * @param platform platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId platform id,can be empty */ public static void reportNotificationArrived(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * Report the arrival of manufacturer channel notification
     * 
     * Report via http/https
     *
     * @param context           not empty
     * @param messageId         Engagelab message id,not empty
     * @param platform          platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId platform id,can be empty
     */
    public static void reportNotificationArrived(Context context, String messageId, byte platform, String platformMessageId)

        
This code block in the floating window

The code example is as follows:

// Report the arrival of the manufacturer's notification, the messageId is "12345", the manufacturer is Xiaomi, and the manufacturer's messageId is "MI-6476RHT25" MTPushPrivatesApi.reportNotificationArrived(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");
              // Report the arrival of the manufacturer's notification, the messageId is "12345", the manufacturer is Xiaomi, and the manufacturer's messageId is "MI-6476RHT25"
    MTPushPrivatesApi.reportNotificationArrived(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");

        
This code block in the floating window

reportNotificationClicked

  • init first, or the call will fail
  • The manufacturer package of Engagelab is not integrated, but it needs to count the click rate of notification by Engagelab. Please call this interface
/** * Submit the manufacturer channel notification and click * *Report via http/https * * @param context not empty * @param messageId Engagelab message id,not empty * @param platform platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId platform message id,can be empty */ public static void reportNotificationClicked(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * Submit the manufacturer channel notification and click
* 
     *Report via http/https
     *
     * @param context           not empty
     * @param messageId         Engagelab message id,not empty
     * @param platform          platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId platform message id,can be empty
     */
    public static void reportNotificationClicked(Context context, String messageId, byte platform, String platformMessageId)

        
This code block in the floating window

The code example is as follows:

// Click to report the manufacturer's notice. The messageId is "12345", the manufacturer is Xiaomi, and the manufacturer's messageId is "MI-6476RHT25" MTPushPrivatesApi.reportNotificationClicked(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");
              // Click to report the manufacturer's notice. The messageId is "12345", the manufacturer is Xiaomi, and the manufacturer's messageId is "MI-6476RHT25"
    MTPushPrivatesApi.reportNotificationClicked(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");

        
This code block in the floating window

reportNotificationDeleted

  • init first, or the call will fail
  • The manufacturer package of Engagelab is not integrated, but Engagelab is required to calculate the deletion rate of notifications. Please call this interface
/** * Report to manufacturer channel notification deletion * * Report via http/https * * @param context not empty * @param messageId Engagelab message id,not empty * @param platform platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId platform message id,can be empty */ public static void reportNotificationDeleted(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * Report to manufacturer channel notification deletion
     * 
     * Report via http/https
     *
     * @param context           not empty
     * @param messageId         Engagelab message id,not empty
     * @param platform          platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId platform message id,can be empty
     */
    public static void reportNotificationDeleted(Context context, String messageId, byte platform, String platformMessageId)

        
This code block in the floating window

The code example is as follows:

// Report the deletion of the vendor notification. The messageId is "12345", the vendor is mi, and the vendor messageId is "MI-6476RHT25" MTPushPrivatesApi.reportNotificationDeleted(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");
              // Report the deletion of the vendor notification. The messageId is "12345", the vendor is mi, and the vendor messageId is "MI-6476RHT25"
    MTPushPrivatesApi.reportNotificationDeleted(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");

        
This code block in the floating window

reportNotificationOpened

  • init first, or the call will fail.
  • The manufacturer package of Engagelab is not integrated, but the opening rate of the notice needs to be calculated by Engagelab. Please call this interface.
  • Some manufacturers (e.g. huawei/opo/vivo) do not notify arrival or click callback. After configuring the activity to notify click jump, you can obtain parameter reports in the jump activity. It is recommended that all manufacturers notify click jump activities to configure.
  • Not required for MTPush4.0.0 or above.
/** * Open the channel notification of the reported manufacturer * *Report via http/https * * @param context not empty * @param messageId Engagelab message id,not empty * @param platform platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId platform message id,can be empty */ public static void reportNotificationOpened(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * Open the channel notification of the reported manufacturer
* 
     *Report via http/https
     *
     * @param context           not empty
     * @param messageId         Engagelab message id,not empty
     * @param platform          platform,value(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId platform message id,can be empty
     */
    public static void reportNotificationOpened(Context context, String messageId, byte platform, String platformMessageId)

        
This code block in the floating window

The code example is as follows:

Bundle bundle = intent.getExtras(); String platformMessage = ""; // huawei if (intent.getData() != null) { platformMessage = intent.getData().toString(); } // Other Mobile manufacturers if (TextUtils.isEmpty(platformMessage) && intent.getExtras() != null) { if (MTGlobal.IS_FOR_JIGUANG) { platformMessage = bundle.getString("JMessageExtra"); }else { platformMessage = bundle.getString("MTMessageExtra"); } } if (TextUtils.isEmpty(platformMessage)) { return; } JSONObject messageJson = new JSONObject(platformMessage); tvMessage.setText(toLogString(messageJson)); // analysis String messageId = messageJson.optString("msg_id"); byte platform = (byte) messageJson.optInt("rom_type"); String title = messageJson.optString("n_title"); String content = messageJson.optString("n_content"); // Click activity to open the report notification. We recommend that you add all vendor redirects. Only MTPush4.0.0 or later is required. MTPushPrivatesApi.reportNotificationOpened(this, messageId, platform, "");
              Bundle bundle = intent.getExtras();
    String platformMessage = "";
    // huawei
    if (intent.getData() != null) {
        platformMessage = intent.getData().toString();
    }
    // Other Mobile manufacturers
    if (TextUtils.isEmpty(platformMessage) && intent.getExtras() != null) {
        if (MTGlobal.IS_FOR_JIGUANG) {
             platformMessage = bundle.getString("JMessageExtra");
        }else {
             platformMessage = bundle.getString("MTMessageExtra");
        }
    }
    if (TextUtils.isEmpty(platformMessage)) {
        return;
    }
    JSONObject messageJson = new JSONObject(platformMessage);
    tvMessage.setText(toLogString(messageJson));
    // analysis
    String messageId = messageJson.optString("msg_id");
    byte platform = (byte) messageJson.optInt("rom_type");
    String title = messageJson.optString("n_title");
    String content = messageJson.optString("n_content");
    // Click activity to open the report notification. We recommend that you add all vendor redirects. Only MTPush4.0.0 or later is required.
    MTPushPrivatesApi.reportNotificationOpened(this, messageId, platform, "");

        
This code block in the floating window

uploadPlatformToken

  • init first, or the call will fail
  • Due to tcp upload, this interface is called after the long connection succeeds, that is, [onConnectStatus] (#onconnectstatus) callback result is true
  • The manufacturer package of Engagelab is not integrated, but the manufacturer message pushed by Engagelab is required
/** * upload Manufacturer token * * upload via tcp * * @param context not empty * @param platform mobile manufacturer,ranges from(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param token token back from mobile manufacturer,not empty * @param region Overseas versions of Xiaomi and oppo need to set the region, fill in such as "US" according to the region of use, etc., fill in null for non-overseas versions */ public static void uploadPlatformToken(Context context, byte platform, String token, String region)
              /**
     * upload Manufacturer token
     * 
     * upload via tcp
     *
     * @param context  not empty
     * @param platform mobile manufacturer,ranges from(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param token    token back from mobile manufacturer,not empty
     * @param region Overseas versions of Xiaomi and oppo need to set the region, fill in such as "US" according to the region of use, etc., fill in null for non-overseas versions
     */
    public static void uploadPlatformToken(Context context, byte platform, String token, String region)

        
This code block in the floating window

The code example is as follows:

// Report the manufacturer token. The manufacturer is mi and the manufacturer token is “MI-6476s-afs-afs-afaR-HT25” MTPushPrivatesApi.uploadPlatformToken(context,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476s-afs-afs-afaR-HT25","US");
              // Report the manufacturer token. The manufacturer is mi and the manufacturer token is “MI-6476s-afs-afs-afaR-HT25”
    MTPushPrivatesApi.uploadPlatformToken(context,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476s-afs-afs-afaR-HT25","US");

        
This code block in the floating window

code

code int Description
SUCCESS 0 Success
TIMEOUT 6002 Configuration timeout. This usually occurs when the network is poor and initialization has not been completed.
UNKNOWN_ERROR 6009 unknown error
INVALID_JSON 6010 invalid json
CONNECT_NOT_ENABLE 6013 CONNECT_NOT_ENABLE

MTCommonReceiver

  • Method callback
  • All method callbacks in this class are in the main proces

onNotificationStatus

  • The current notification switch status is called back after the sdk init
  • Callback is triggered only when the notification switch changes
/** * Application notification switch status callback * * @param context not empty * @param enable Is the notification switch on? true means yes,false means no */ @Override public void onNotificationStatus(Context context, boolean enable)
              /**
     * Application notification switch status callback
     *
     * @param context not empty
     * @param enable  Is the notification switch on? true means yes,false means no
     */
    @Override
    public void onNotificationStatus(Context context, boolean enable)

        
This code block in the floating window

onConnectStatus

/** * persistent connection success * * After initialization, the connection is initiated. If the connection succeeds or fails, a callback is returned. * * @param context not empty * @param enable Is the persistent connection successful? true means yes,false means no */ public void onConnectStatus(Context context, boolean enable)
              /**
     * persistent connection success
     *
     * After initialization, the connection is initiated. If the connection succeeds or fails, a callback is returned.
     *
     * @param context not empty
     * @param enable  Is the persistent connection successful? true means yes,false means no   
     */		
        public void onConnectStatus(Context context, boolean enable)

        
This code block in the floating window

onNotificationArrived

  • Engagelab/Xiaomi/Meizu support (google channel needs app running in front)
  • See NotificationMessage for notificationMessage
/** * Notification message delivery * * This method is called back when a pushed notification message is delivered * * @param context not empty * @param notificationMessage Notification message */ public void onNotificationArrived(Context context, NotificationMessage notificationMessage)
              /**
     * Notification message delivery
     *
     * This method is called back when a pushed notification message is delivered
     *
     * @param context 						not empty
     * @param notificationMessage Notification message  
     */				
        public void onNotificationArrived(Context context, NotificationMessage notificationMessage)

        
This code block in the floating window

onNotificationClicked

  • Engagelab/Xiaomi/Meizu support (google channel needs app running in front).
  • See NotificationMessage for notificationMessage.
/** * Notification message click * * This method is called back when a pushed notification message is clicked * * @param context not empty * @param notificationMessage Notification message */ public void onNotificationClicked(Context context, NotificationMessage notificationMessage)
              /**
     * Notification message click
     *
         * This method is called back when a pushed notification message is clicked
         *
     * @param context 						not empty
     * @param notificationMessage Notification message  
     */				
        public void onNotificationClicked(Context context, NotificationMessage notificationMessage)

        
This code block in the floating window

onNotificationDeleted

  • Only when the notification message of the Engagelab channel is deleted.
  • See NotificationMessage for notificationMessage.
  • The application cannot be called back when the application is not active.
/** * Notification message deletion * * This method is called back when the pushed notification message is deleted * * @param context not empty * @param notificationMessage Notification message */ public void onNotificationDeleted(Context context, NotificationMessage notificationMessage)
              /**
     * Notification message deletion
     * 
         * This method is called back when the pushed notification message is deleted
         *
     * @param context 						not empty
     * @param notificationMessage Notification message  
     */				
        public void onNotificationDeleted(Context context, NotificationMessage notificationMessage)

        
This code block in the floating window

onCustomMessage

  • Custom messages are not displayed in the notification bar.
  • Only when the notification message of the Engagelab channel is deleted.
  • See CustomMessage for customMessage.
/** * Custom message delivery * * This method is called back when a custom message is sent * * @param context not empty * @param customMessage Custom message */ public void onCustomMessage(Context context, CustomMessage customMessage)
              /**
     * Custom message delivery
     *
     * This method is called back when a custom message is sent
     *
     * @param context 			not empty
     * @param customMessage Custom message  
     */				
        public void onCustomMessage(Context context, CustomMessage customMessage)

        
This code block in the floating window

onPlatformToken

  • After the manufacturer channel is correctly integrated, this callback occurs after the persistent connection is successful.
  • See PlatformTokenMessage for onPlatformToken
/** * Manufacturer operation message * * @param context ApplicationContext Object * @param platformTokenMessage manufacturer token message */ public void onPlatformToken(Context context, PlatformTokenMessage platformMessage)
              /**
     * Manufacturer operation message
     *
     * @param context         ApplicationContext Object
     * @param platformTokenMessage   manufacturer token message
     */
    public void onPlatformToken(Context context, PlatformTokenMessage platformMessage)

        
This code block in the floating window

NotificationMessage

  • Notification message
Attribute Type Description
messageId String required,EngagelabmessageId,Used for message tracking and statistics. Not empty. If it is empty, no notification will be displayed
overrideMessageId String EngagelaboverrideMessageId,for Message Tracking and statistics
platform byte Manufacturer Type
  • Engagelab is by default,MTPushPrivatesApi.PLATFORM_DEFAULT:0
  • XIAOMI,MTPushPrivatesApi.PLATFORM_XIAOMI:1
  • HUAWEI,MTPushPrivatesApi.PLATFORM_HUAWEI:2
  • MEIZU,MTPushPrivatesApi.PLATFORM_MEIZU:3
  • oppo,MTPushPrivatesApi.PLATFORM_OPPO:4
  • vivo,MTPushPrivatesApi.PLATFORM_VIVO:5
  • google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
  • platformMessageId String Manufacturer messageId,for manufacturer message tracking and statistics
    notificationId int Notification id. Call clearNotification to cancel
    smallIcon String small icon,use drawable/mtpush_notification_icon.png by default
    largeIcon String large icon,Generally, it is on the right side of the notification
    title String The notification Title. If empty, the application name is used.
    content String Required,notification content,not empty. If empty, no notification is displayed.
    extras Bundle Additional fields, key/value format is String
    builderId int The id of the notification style. Call the setNotificationLayout to set the notification style. The system style is used by default
    style int The notification style.Default value: 0.
  • Large text style,NOTIFICATION_STYLE_BIG_TEXT:1.
  • Inbox style,NOTIFICATION_STYLE_INBOX:2.
  • Large picture style,NOTIFICATION_STYLE_BIG_PICTURE:3.
  • bigText String Large Text. The style parameter is NOTIFICATION_STYLE_BIG_TEXT
    inbox String[] Inbox. The style is NOTIFICATION_STYLE_INBOX
    bigPicture String Large image. The style is NOTIFICATION_STYLE_BIG_PICTURE
    priority int The urgency of the Notification. The default value is 0.
  • LOW.The Notification does not have LED lights, vibration and ringtones. Notification.PRIORITY_LOW:-1
  • Normal. notifications can be LED lights, vibration and ringtones, Notification.PRIORITY_DEFAULT:0
  • Advanced. Notifications can be LED lights, vibration and ringtones, and can also pop up floating windows. Notification.PRIORITY_HIGH:1
  • defaults int Notifications are used for ringtones, vibration, and LED lights. The default value is Notification.DEFAULT_ALL:-1 ringtone, Notification.DEFAULT_SOUND:1 vibration, Notification.DEFAULT_VIBRATE:2led, Notification.DEFAULT_LIGHTS:4 three scenes can be freely combined. For example, when it is 7, it indicates that the ring, vibration, and LED lights all have Android8.0. This attribute follows the channel.
    category String The Notification type, which is used to sort or filter the Notification bar. A wide range of Notification types are available, such as Notification.CATEGORY_ALARM and Notification#CATEGORY_CALL
    sound String The ringtone attached to the notification. The ringtone file Android8.0 must be stored in the res/raw directory in advance. The ringtone follows the channel. If the ringtone is not set in the channel used by the notification, this notification does not take effect on the custom ringtone. We recommend that you set the ringtone in the channel in advance. When the notification is sent later, the sound is consistent with the ringtone in the channelId.
    channelId String It is required from Android8.0. If you do not set the sdk in advance, the sdk will help you set it up (only the Engagelab channel and the google channel when the application is in front desk).
    intentUri String Click the redirection after the notification. Currently, only activity is supported. activity redirection is obtained by usingIntent.toURI()
    badge int The number of corner labels added to this notification belongs to the accumulation logic. The value must be greater than 0. Otherwise, it is invalid. We recommend that you enter 1. Only Huawei and Xiaomi take effect. After Xiaomi clicks the notification, the number of corner labels will be automatically reduced by 1. After Huawei clicks the notification, the number of corner labels will not be automatically reduced by 1. We recommend that you call setNotificationBadge to set

    CustomMessage

    • Custom message
    Attribute Type Description
    messageId String Required, EngagelabmessageId, used for Message Tracking and statistics,not empty
    platform byte Manufacturer type.
  • Default value:Engagelab,MTPushPrivatesApi.PLATFORM_DEFAULT:0
  • XIAOMI,MTPushPrivatesApi.PLATFORM_XIAOMI:1
  • HUAWEI,MTPushPrivatesApi.PLATFORM_HUAWEI:2
  • MEIZU,MTPushPrivatesApi.PLATFORM_MEIZU:3
  • oppo,MTPushPrivatesApi.PLATFORM_OPPO:4
  • vivo,MTPushPrivatesApi.PLATFORM_VIVO:5
  • google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
  • platformMessageId String Manufacturer messageId,Used for vendor message tracking and statistics
    title String Message title
    content String Message content
    contentType String Message type
    extras Bundle Extra field,key/value format is String

    PlatformTokenMessage

    • platform token
    Attribute Type Description
    platform byte Type
  • Default value: Engagelab,MTPushPrivatesApi.PLATFORM_DEFAULT:0
  • XIAOMI,MTPushPrivatesApi.PLATFORM_XIAOMI:1
  • HUAWEI,MTPushPrivatesApi.PLATFORM_HUAWEI:2
  • MEIZU,MTPushPrivatesApi.PLATFORM_MEIZU:3
  • oppo,MTPushPrivatesApi.PLATFORM_OPPO:4
  • vivo,MTPushPrivatesApi.PLATFORM_VIVO:5
  • google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
  • token String returned token
    在文档中心打开