logo

MTPush-API

อัพเดทล่าสุด :2024-09-18

MTCorePrivatesApi

  • Mainly used for information configuration.
  • All methods need to be called in the main process. Please do not judge whether the process will place them in the child process before the method is called, or the call error will occur.

configAppKey

  • You need to call in the Application. onCreate() method
  • Please call before [init] (#init)
/** *Configure the application key without using the configuration in AndroidManifest.xml * *You need to call in the Application. onCreate() method *Please call before [init] (# init) * *@ param context is not empty *@ param appKey is not empty */ Public static void configAppKey (Context context, String appKey)
          /**
*Configure the application key without using the configuration in AndroidManifest.xml
*
*You need to call in the Application. onCreate() method
*Please call before [init] (# init)
*
*@ param context is not empty
*@ param appKey is not empty
*/
Public static void configAppKey (Context context, String appKey)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

MTCorePrivatesApi. configAppKey (this, "your appkey");
          MTCorePrivatesApi. configAppKey (this, "your appkey");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

configAppChannel

  • Needs to be called in the Application.onCreate() method
  • Please call it before init
/** * Configure the application channel, not using the configuration in AndroidManifest.xml * Needs to be called in the Application.onCreate() method * Needs to be used before init, and must be used within Application.onCreate * * @param context Not empty * @param appChannel Not empty */ public static void configAppChannel(Context context, String appChannel)
               /**
         * Configure the application channel, not using the configuration in AndroidManifest.xml
         * Needs to be called in the Application.onCreate() method
         * Needs to be used before init, and must be used within Application.onCreate
         *
         * @param context    Not empty
         * @param appChannel Not empty
         */
    public static void configAppChannel(Context context, String appChannel)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Code example:

MTCorePrivatesApi.configAppChannel(this,"your_appChannel");
          MTCorePrivatesApi.configAppChannel(this,"your_appChannel");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

###configAppSiteName

  • You need to call in the Application. onCreate() method
  • Please call before [init] (# init)
/** *Configure the data center site name without using the configuration in AndroidManifest.xml *The currently available nodes are Singapore, USA_Virginia, DEU_Frankfurt, and HongKong. *You need to call in the Application. onCreate() method *Please call before [init] (# init) * *@ param context is not empty *@ param appSiteName is not empty */ Public static void configAppSiteName (Context context, String appSiteName)
          /**
*Configure the data center site name without using the configuration in AndroidManifest.xml
*The currently available nodes are Singapore, USA_Virginia, DEU_Frankfurt, and HongKong.
*You need to call in the Application. onCreate() method
*Please call before [init] (# init)
*
*@ param context is not empty
*@ param appSiteName is not empty
*/
Public static void configAppSiteName (Context context, String appSiteName)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

MTCorePrivatesApi. configAppSiteName (this, "Your Platform Data Center Site Name");
          MTCorePrivatesApi. configAppSiteName (this, "Your Platform Data Center Site Name");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

configHeartbeatInterval

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

  • The demo sets the heartbeat interval to 3 minutes
MTCorePrivatesApi.configHeartbeatInterval(this,3*60*1000);
          MTCorePrivatesApi.configHeartbeatInterval(this,3*60*1000);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

configConnectRetryCount

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

*Demonstration set the number of reconnections to 10 times

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setTcpSSl

  • need to be called in the Application.onCreate() method
  • Please call before init
/** * Set whether the long connection is encrypted, the default is not encrypted * * Need to be called in the Application.onCreate() method * * @param isSSL true encryption, false no encryption */ public static void setTcpSSl(boolean isSSL)
               /**
      * Set whether the long connection is encrypted, the default is not encrypted
      *
      * Need to be called in the Application.onCreate() method
      *
      * @param isSSL true encryption, false no encryption
      */
     public static void setTcpSSl(boolean isSSL)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

  • demo setup encryption
MTCorePrivatesApi.setTcpSSl(true);
          MTCorePrivatesApi.setTcpSSl(true);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

configDebugMode

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

  • sdk works in two processes, the main process and the child process, the child process name is the process attribute name of the MTCommonService subclass service
  • sdk log tag is "ENGAGELAB-PRIVATES"
  • The logs of udp/tcp/http related operations are all in the child process
  • Therefore, if the message cannot be pushed, please enable the debug mode first, then go to the subprocess to obtain the log with the tag "ENGAGELAB-PRIVATES", and provide it to technical support for analysis
// It is recommended to set it to true when the application is not online, which is convenient for integration MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // It is recommended to set it to false after the application is launched MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), false);
          // It is recommended to set it to true when the application is not online, which is convenient for integration
MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true);

// It is recommended to set it to false after the application is launched
MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), false);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

configSM4

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

getUserId

When the return value is empty, you need to pay attention to whether the environment is configured and whether the initialization is called

If you check the configuration is correct, it may still be in the process of connecting, you can get it when onConnectStatus returns true

/** * Get the userId of the current device, which is the unique identifier of Engagelab, which can be used to push * * @param context is not empty * @return userId */ public static String getUserId(Context context)
               /**
      * Get the userId of the current device, which is the unique identifier of Engagelab, which can be used to push
      *
      * @param context is not empty
      * @return userId
      */
     public static String getUserId(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

getRegistrationId

When the return value is empty, you need to pay attention to whether the environment is configured and whether the initialization is called

If you check the configuration is correct, it may still be in the process of connecting, you can get it when onConnectStatus returns true

/** * Get the registrationId of the current device, the unique identifier of Engagelab, which can be used to push * * @param context is not empty * @return registrationId */ public static String getRegistrationId(Context context)
               /**
      * Get the registrationId of the current device, the unique identifier of Engagelab, which can be used to push
      *
      * @param context is not empty
      * @return registrationId
      */
     public static String getRegistrationId(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

MTPushPrivatesApi

  • is mainly used for push function
  • All methods need to be called in the main process, please do not judge the process before calling the method and place it in the child process, otherwise the call will go wrong

configOldPushVersion

  • Backstage has not upgraded the tag: V3.5.4-newportal-20210823-gamma.57 version, the front end must call this method, otherwise there is a problem with the notification click jump
  • Called in the Application.onCreate() method
  • Please call before init
/** * Configure the push version number as 3.9.X * * @param context is not empty */ public static void configOldPushVersion(Context context)
               /**
      * Configure the push version number as 3.9.X
      *
      * @param context is not empty
      */
     public static void configOldPushVersion(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows:

public class ExampleApplication extends Application { @Override public void onCreate() { // turn on debug mode MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // Use the old version of the notification to click to jump 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);
     // Use the old version of the notification to click to jump
     MTPushPrivatesApi.configOldPushVersion(context.getApplicationContext());
     // initialization
         MTPushPrivatesApi.init(context.getApplicationContext());
     }
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setEnablePushTextToSpeech

/** * Voice broadcasting feature settings, requires importing the voice package (mt-sdk-sound-x.x.x.aar) * * @param context Must not be null * @param enable true to enable, false to disable, default is false */ public static void setEnablePushTextToSpeech(Context context, boolean enable)
              /**
     * Voice broadcasting feature settings, requires importing the voice package (mt-sdk-sound-x.x.x.aar)
     *
     * @param context      Must not be null
     * @param enable true to enable, false to disable, default is false
     */
    public static void setEnablePushTextToSpeech(Context context, boolean enable)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Example code is as follows:

MTPushPrivatesApi.setEnablePushTextToSpeech(context,true);
              MTPushPrivatesApi.setEnablePushTextToSpeech(context,true);   

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

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 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 applicationContext object
      */
     public static void init(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

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());
     }
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

goToAppNotificationSettings

  • After starting the sdk, you can call back the result according to onNotificationStatus, and then decide whether you need to call this excuse
/** * Go to the notification switch settings page * * @param context is not empty */ public static void goToAppNotificationSettings(Context context)
               /**
      * Go to the notification switch settings page
      *
      * @param context is not empty
      */
     public static void goToAppNotificationSettings(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

turnOnPush

  • Generally used to enable push after calling turnOffPush
  • Repeated calling will only take effect once, if it is already enabled, it will not take effect again
  • If there is no problem with the environment, onConnectStatus will call back the result
  • Currently supported channels: Engagelab/Huawei/Xiaomi/Meizu/oppo/vivo
/** * Enable Push push, and the persistent storage switch status is true, the default is true * * @param context cannot be empty */ public static void turnOnPush(Context context)
               /**
      * Enable Push push, and the persistent storage switch status is true, the default is true
      *
      * @param context cannot be empty
      */
     public static void turnOnPush(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

// Turn on the push, which is turned on by default MTPushPrivatesApi.turnOnPush(context); // After inheriting MTCommonReceiver, rewrite the onConnectStatus method to obtain the connection status of the long connection. If enable is true, it means that it has been successfully opened @Override public void onConnectStatus(Context context, boolean enable){ if(enable){ // enable push push successfully } }
          // Turn on the push, which is turned on by default
MTPushPrivatesApi.turnOnPush(context);

// After inheriting MTCommonReceiver, rewrite the onConnectStatus method to obtain the connection status of the long connection. If enable is true, it means that it has been successfully opened
@Override
public void onConnectStatus(Context context, boolean enable){
     if(enable){
         // enable push push successfully
     }
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

turnOffPush

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

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

// After inheriting MTCommonReceiver, rewrite the onConnectStatus method to get the long connection status. If enable is false, it means that it has been closed successfully
@Override
public void onConnectStatus(Context context, boolean enable){
     if(!enable){
         // close push push successfully
     }
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

addTag

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onTagMessage will call back the result
/** * Add specified tag, accumulation logic, the previously set tag still exists * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation * @param tags tag array, the length of each tag name is limited to 40 bytes, a maximum of 1000 tags can be set, and the total length of a single operation cannot exceed 5000 bytes */ public static void addTag(Context context, int sequence, String... tags)
               /**
      * Add specified tag, accumulation logic, the previously set tag still exists
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      * @param tags tag array, the length of each tag name is limited to 40 bytes, a maximum of 1000 tags can be set, and the total length of a single operation cannot exceed 5000 bytes
      */
     public static void addTag(Context context, int sequence, String... tags)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

// Define a constant here, which represents adding the specified tag operation private static final int SEQUENCE_TAG_ADD = 1; // Add tags: "china","guangdong","shenzhen" MTPushPrivatesApi.addTag(context,SEQUENCE_TAG_ADD,"china","guangdong","shenzhen") // After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_ADD){ // The specified tag is added successfully. At this time, you can view the tag array of the successful operation String[] tags = tagMessage. getTags(); } }
          // Define a constant here, which represents adding the specified tag operation
private static final int SEQUENCE_TAG_ADD = 1;
// Add tags: "china","guangdong","shenzhen"
MTPushPrivatesApi.addTag(context,SEQUENCE_TAG_ADD,"china","guangdong","shenzhen")

// After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback
@Override
public void onTagMessage(Context context, TagMessage tagMessage){
if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
// tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code
return;
}
if(tagMessage.getSequence() == SEQUENCE_TAG_ADD){
// The specified tag is added successfully. At this time, you can view the tag array of the successful operation
String[] tags = tagMessage. getTags();
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

deleteTag

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onTagMessage will call back the result
/** * Delete the specified tag, delete the logic, and the specified tag will be deleted * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation * @param tags tag array, the length of each tag name is limited to 40 bytes, a maximum of 1000 tags can be set, and the total length of a single operation cannot exceed 5000 bytes */ public static void deleteTag(Context context, int sequence, String... tags)
               /**
      * Delete the specified tag, delete the logic, and the specified tag will be deleted
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      * @param tags tag array, the length of each tag name is limited to 40 bytes, a maximum of 1000 tags can be set, and the total length of a single operation cannot exceed 5000 bytes
      */
     public static void deleteTag(Context context, int sequence, String... tags)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows:

// Define a constant here, which represents the operation of deleting the specified tag private static final int SEQUENCE_TAG_DELETE = 2; // Delete tags: "china","guangdong","shenzhen" MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE,"china","guangdong","shenzhen") // After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE){ // Delete the specified tag successfully, at this time, you can view the tag array of the successful operation String[] tags = tagMessage. getTags(); } }
          
// Define a constant here, which represents the operation of deleting the specified tag
private static final int SEQUENCE_TAG_DELETE = 2;
// Delete tags: "china","guangdong","shenzhen"
MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE,"china","guangdong","shenzhen")

// After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback
@Override
public void onTagMessage(Context context, TagMessage tagMessage){
if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
// tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code
return;
}
if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE){
// Delete the specified tag successfully, at this time, you can view the tag array of the successful operation
String[] tags = tagMessage. getTags();
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

updateTag

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onTagMessage will call back the result
/** * Update the specified tag, override the logic, and the previously added tag will be cleared * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation * @param tags tag array, the length of each tag name is limited to 40 bytes, a maximum of 1000 tags can be set, and the total length of a single operation cannot exceed 5000 bytes */ public static void updateTag(Context context, int sequence, String... tags)
               /**
      * Update the specified tag, override the logic, and the previously added tag will be cleared
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      * @param tags tag array, the length of each tag name is limited to 40 bytes, a maximum of 1000 tags can be set, and the total length of a single operation cannot exceed 5000 bytes
      */
     public static void updateTag(Context context, int sequence, String... tags)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows:

// Define a constant here, which represents the operation of updating the specified tag private static final int SEQUENCE_TAG_UPDATE = 3; // Update tag: "beijing","shanghai","guangzhou","shenzhen", the previously set tag will be invalid MTPushPrivatesApi.updateTag(context,SEQUENCE_TAG_UPDATE,"beijing","shanghai","guangzhou","shenzhen") // After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_UPDATE){ // Update the specified tag successfully, and you can view the tag array with successful operation at this time String[] tags = tagMessage. getTags(); } }
          // Define a constant here, which represents the operation of updating the specified tag
private static final int SEQUENCE_TAG_UPDATE = 3;
// Update tag: "beijing","shanghai","guangzhou","shenzhen", the previously set tag will be invalid
MTPushPrivatesApi.updateTag(context,SEQUENCE_TAG_UPDATE,"beijing","shanghai","guangzhou","shenzhen")

// After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback
@Override
public void onTagMessage(Context context, TagMessage tagMessage){
if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
// tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code
return;
}
if(tagMessage.getSequence() == SEQUENCE_TAG_UPDATE){
// Update the specified tag successfully, and you can view the tag array with successful operation at this time
String[] tags = tagMessage. getTags();
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

queryTag

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onTagMessage will call back the result
/** * Query the specified tag * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation * @param tag, the length of each tag name is limited to 40 bytes */ public static void queryTag(Context context, int sequence, String tag)
               /**
      * Query the specified tag
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      * @param tag, the length of each tag name is limited to 40 bytes
      */
     public static void queryTag(Context context, int sequence, String tag)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows

// Define a constant here, which represents the query specified tag operation private static final int SEQUENCE_TAG_QUERY = 4; // query label MTPushPrivatesApi.queryTag(context,SEQUENCE_TAG_QUERY,"china") // After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_QUERY){ // Query the specified tag successfully, at this time, you can view the tag and status of the successful operation String tag = tagMessage. getQueryTag(); boolean valid = tagMessage.isQueryTagValid(); } }
          // Define a constant here, which represents the query specified tag operation
private static final int SEQUENCE_TAG_QUERY = 4;
// query label
MTPushPrivatesApi.queryTag(context,SEQUENCE_TAG_QUERY,"china")

// After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback
@Override
public void onTagMessage(Context context, TagMessage tagMessage){
if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
// tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code
return;
}
if(tagMessage.getSequence() == SEQUENCE_TAG_QUERY){
// Query the specified tag successfully, at this time, you can view the tag and status of the successful operation
String tag = tagMessage. getQueryTag();
boolean valid = tagMessage.isQueryTagValid();
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

deleteAllTag

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onTagMessage will call back the result
/** * Delete all tags, clear the logic, and delete all tags * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation */ public static void deleteAllTag(Context context, int sequence, String... tags)
               /**
      * Delete all tags, clear the logic, and delete all tags
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      */
     public static void deleteAllTag(Context context, int sequence, String... tags)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows:

// Define a constant here to represent delete all tag operations private static final int SEQUENCE_TAG_DELETE_ALL = 5; // remove all tags MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE_ALL) // After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){ // delete all tags successfully } }
          // Define a constant here to represent delete all tag operations
private static final int SEQUENCE_TAG_DELETE_ALL = 5;
// remove all tags
MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE_ALL)

// After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback
@Override
public void onTagMessage(Context context, TagMessage tagMessage){
if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
// tag operation failed, detailed error information can be found in MTPushPrivatesApi.Code
return;
}
if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){
// delete all tags successfully
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

queryAllTag

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onTagMessage will call back the result
/** * Query all tags, get logic, and get all tags * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation */ public static void queryAllTag(Context context, int sequence, String... tags)
               /**
      * Query all tags, get logic, and get all tags
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      */
     public static void queryAllTag(Context context, int sequence, String... tags)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The code example is as follows:

// Define a constant here, which represents querying all tag operations private static final int SEQUENCE_TAG_QUERY_ALL = 6; // query all tags MTPushPrivatesApi.queryAllTag(context,SEQUENCE_TAG_QUERY_ALL) // After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // The tag operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){ // Query all tags successfully, at this time, you can view the tag array with successful operation String[] tags = tagMessage. getTags(); } }
          
// Define a constant here, which represents querying all tag operations
private static final int SEQUENCE_TAG_QUERY_ALL = 6;
// query all tags
MTPushPrivatesApi.queryAllTag(context,SEQUENCE_TAG_QUERY_ALL)

// After inheriting MTCommonReceiver, override the onTagMessage method to get the tag operation callback
@Override
public void onTagMessage(Context context, TagMessage tagMessage){
if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
// The tag operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code
return;
}
if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){
// Query all tags successfully, at this time, you can view the tag array with successful operation
String[] tags = tagMessage. getTags();
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setAlias

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onAliasMessage will call back the result
/** * set aliases * * It is recommended to use different aliases for different users in the same application. This way, users are uniquely identified by their aliases whenever possible * * Do not limit an alias and only specify one user * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation * @param alias Valid alias composition: letters (case-sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|. Restrictions: The length of alias names is limited to 40 bytes (UTF-8 encoding is required to determine the length) * */ public static void setAlias(Context context, int sequence, String alias)
               /**
      * set aliases
      *
      * It is recommended to use different aliases for different users in the same application. This way, users are uniquely identified by their aliases whenever possible
      *
      * Do not limit an alias and only specify one user
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      * @param alias Valid alias composition: letters (case-sensitive), numbers, underscores, Chinese characters, special characters @!#$&*+=.|. Restrictions: The length of alias names is limited to 40 bytes (UTF-8 encoding is required to determine the length)
      *
      */
     public static void setAlias(Context context, int sequence, String alias)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Define a constant here, which represents setting alias operation private static final int SEQUENCE_ALIAS_SET = 7; // Set alias: "young" MTPushPrivatesApi.setAlias(context,SEQUENCE_ALIAS_SET,"young") // After inheriting MTCommonReceiver, override the onAliasMessage method to get the alias operation callback @Override public void onAliasMessage(Context context, AliasMessage aliasMessage){ if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){ // The alias operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code return; } if(aliasMessage.getSequence() == SEQUENCE_ALIAS_SET){ // The alias is set successfully, and you can view the alias of the successful operation at this time String alias = aliasMessage. getAlias(); } }
          // Define a constant here, which represents setting alias operation
private static final int SEQUENCE_ALIAS_SET = 7;
// Set alias: "young"
MTPushPrivatesApi.setAlias(context,SEQUENCE_ALIAS_SET,"young")

// After inheriting MTCommonReceiver, override the onAliasMessage method to get the alias operation callback
@Override
public void onAliasMessage(Context context, AliasMessage aliasMessage){
if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){
// The alias operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code
return;
}
if(aliasMessage.getSequence() == SEQUENCE_ALIAS_SET){
// The alias is set successfully, and you can view the alias of the successful operation at this time
String alias = aliasMessage. getAlias();
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

getAlias

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onAliasMessage will call back the result
/** * get alias * * It is recommended to use different aliases for different users in the same application. This way, users are uniquely identified by their aliases whenever possible * * Do not limit an alias and only specify one user * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation */ public static void getAlias(Context context, int sequence)
               /**
      * get alias
      *
      * It is recommended to use different aliases for different users in the same application. This way, users are uniquely identified by their aliases whenever possible
      *
      * Do not limit an alias and only specify one user
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      */
     public static void getAlias(Context context, int sequence)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows:

// Define a constant here, which represents the operation of obtaining alias private static final int SEQUENCE_ALIAS_GET = 8; // get alias MTPushPrivatesApi.getAlias(context,SEQUENCE_ALIAS_GET) // After inheriting MTCommonReceiver, override the onAliasMessage method to get the alias operation callback @Override public void onAliasMessage(Context context, AliasMessage aliasMessage){ if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){ // The alias operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code return; } if(aliasMessage.getSequence() == SEQUENCE_ALIAS_GET){ // Get the alias successfully, you can view the alias of the successful operation at this time String alias = aliasMessage. getAlias(); } }
          // Define a constant here, which represents the operation of obtaining alias
private static final int SEQUENCE_ALIAS_GET = 8;
// get alias
MTPushPrivatesApi.getAlias(context,SEQUENCE_ALIAS_GET)

// After inheriting MTCommonReceiver, override the onAliasMessage method to get the alias operation callback
@Override
public void onAliasMessage(Context context, AliasMessage aliasMessage){
if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){
// The alias operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code
return;
}
if(aliasMessage.getSequence() == SEQUENCE_ALIAS_GET){
// Get the alias successfully, you can view the alias of the successful operation at this time
String alias = aliasMessage. getAlias();
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

clearAlias

  • Please init first, otherwise the call is invalid
  • If there is no problem with the environment, onAliasMessage will call back the result
/** * Clear aliases * * It is recommended to use different aliases for different users in the same application. This way, users are uniquely identified by their aliases whenever possible * * Do not limit an alias and only specify one user * * @param context cannot be empty * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation */ public static void clearAlias(Context context, int sequence)
               /**
      * Clear aliases
      *
      * It is recommended to use different aliases for different users in the same application. This way, users are uniquely identified by their aliases whenever possible
      *
      * Do not limit an alias and only specify one user
      *
      * @param context cannot be empty
      * @param sequence User-defined operation sequence number, returned together with the operation result, used to identify the uniqueness of an operation
      */
     public static void clearAlias(Context context, int sequence)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows:

// Define a constant here to represent clear alias operation private static final int SEQUENCE_ALIAS_CLEAR = 7; // clear aliases MTPushPrivatesApi.clearAlias(context,SEQUENCE_ALIAS_CLEAR) // After inheriting MTCommonReceiver, override the onAliasMessage method to get the alias operation callback @Override public void onAliasMessage(Context context, AliasMessage aliasMessage){ if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){ // The alias operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code return; } if(aliasMessage.getSequence() == SEQUENCE_ALIAS_CLEAR){ // Clear alias successfully } }
          // Define a constant here to represent clear alias operation
private static final int SEQUENCE_ALIAS_CLEAR = 7;
// clear aliases
MTPushPrivatesApi.clearAlias(context,SEQUENCE_ALIAS_CLEAR)

// After inheriting MTCommonReceiver, override the onAliasMessage method to get the alias operation callback
@Override
public void onAliasMessage(Context context, AliasMessage aliasMessage){
if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){
// The alias operation failed, for detailed error information, please refer to MTPushPrivatesApi.Code
return;
}
if(aliasMessage.getSequence() == SEQUENCE_ALIAS_CLEAR){
// Clear alias successfully
}
}

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setNotificationShowTime

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel/google channel when the app is in the foreground (shown by Engagelab)
/** * Set the notification display time, which will be displayed at any time by default * * @param context is not empty * @param beginHour The start time (in 24-hour format, range 0 to 23) to allow notification display * @param endHour Allows the end time of notification display (24-hour clock, range is 0 to 23), beginHour cannot be greater than or equal to endHour * @param weekDays weekday array that allows notifications to be displayed (7-day system, ranging from 1 to 7), an empty array means that no notifications will be displayed at any time */ public static void setNotificationShowTime(Context context, int beginHour, int endHour, int... weekDays)
               /**
      * Set the notification display time, which will be displayed at any time by default
      *
      * @param context is not empty
      * @param beginHour The start time (in 24-hour format, range 0 to 23) to allow notification display
      * @param endHour Allows the end time of notification display (24-hour clock, range is 0 to 23), beginHour cannot be greater than or equal to endHour
      * @param weekDays weekday array that allows notifications to be displayed (7-day system, ranging from 1 to 7), an empty array means that no notifications will be displayed at any time
      */
     public static void setNotificationShowTime(Context context, int beginHour, int endHour, int... weekDays)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Set the notification display time from 9 am to 9 pm on 1/3/5/7 every week MTPushPrivatesApi.setNotificationShowTime(context, 9, 21, 1,3,5,7);
               // Set the notification display time from 9 am to 9 pm on 1/3/5/7 every week
     MTPushPrivatesApi.setNotificationShowTime(context, 9, 21, 1,3,5,7);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

resetNotificationShowTime

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel/google channel when the app is in the foreground (shown by Engagelab)
/** * Reset the notification display time, it will be displayed at any time by default * * @param context is not empty */ public static void resetNotificationShowTime(Context context)
               /**
      * Reset the notification display time, it will be displayed at any time by default
      *
      * @param context is not empty
      */
     public static void resetNotificationShowTime(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Reset the notification display time, which is displayed at any time by default MTPushPrivatesApi.resetNotificationShowTime(context);
               // Reset the notification display time, which is displayed at any time by default
     MTPushPrivatesApi.resetNotificationShowTime(context);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setNotificationSilenceTime

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel/google channel when the app is in the foreground (shown by Engagelab)
/** * Set the notification silent time, the default is not silent at any time * * @param context is not empty * @param beginHour The start time to allow notification silence, in hours (24-hour format, range 0 to 23) * @param beginMinute Allows the start time of notification silence, in minutes (60 minutes, range is 0 to 59 ) * @param endHour The end time to allow notification silence, in hours (24-hour clock, range 0 to 23 ) * @param endMinute allows the end time of notification silence, in minutes (60 minutes, range is 0 to 59) */ public static void setNotificationSilenceTime(Context context, int beginHour, int beginMinute, int endHour, int endMinute)
               /**
      * Set the notification silent time, the default is not silent at any time
      *
      * @param context is not empty
      * @param beginHour The start time to allow notification silence, in hours (24-hour format, range 0 to 23)
      * @param beginMinute Allows the start time of notification silence, in minutes (60 minutes, range is 0 to 59 )
      * @param endHour The end time to allow notification silence, in hours (24-hour clock, range 0 to 23 )
      * @param endMinute allows the end time of notification silence, in minutes (60 minutes, range is 0 to 59)
      */
     public static void setNotificationSilenceTime(Context context, int beginHour, int beginMinute, int endHour, int endMinute)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

resetNotificationSilenceTime

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel/google channel when the app is in the foreground (shown by Engagelab)
/** * Reset the notification silent time, the default is not silent at any time * * @param context is not empty */ public static void resetNotificationSilenceTime(Context context)
               /**
      * Reset the notification silent time, the default is not silent at any time
      *
      * @param context is not empty
      */
     public static void resetNotificationSilenceTime(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Reset the notification silent time, the default is not silent at any time MTPushPrivatesApi.resetNotificationSilenceTime(context);
               // Reset the notification silent time, the default is not silent at any time
     MTPushPrivatesApi.resetNotificationSilenceTime(context);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setNotificationLayout

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel
/** * Set a custom notification layout, the system notification layout is used by default * * @param context is not empty * @param builderId build id * @param notificationLayout Object of custom notification layout, not empty */ public static void setNotificationLayout(Context context, int builderId, NotificationLayout notificationLayout)
               /**
      * Set a custom notification layout, the system notification layout is used by default
      *
      * @param context is not empty
      * @param builderId build id
      * @param notificationLayout Object of custom notification layout, not empty
      */
     public static void setNotificationLayout(Context context, int builderId, NotificationLayout notificationLayout)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Define a constant here, representing the build id private static final int BUILDER_ID = 11; // Build a notificationLayout NotificationLayout notificationLayout = new NotificationLayout() .setLayoutId(R.layout.custom_notification_layout) // layout layout_id .setIconViewId(R.id.iv_notification_icon) // notification icon view_id .setIconResourceId(R.drawable.mtpush_notification_icon) // notification icon source_id .setTitleViewId(R.id.tv_notification_title) // notification title view_id .setContentViewId(R.id.tv_notification_content) // notification content view_id .setTimeViewId(R.id.tv_notification_time); // notification time view_id // Set the custom layout with the build id as BUILDER_ID, and specify builderId as BUILDER_ID when sending the notification to change the layout of the notification MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, notificationLayout);
          // Define a constant here, representing the build id
private static final int BUILDER_ID = 11;

// Build a notificationLayout
     NotificationLayout notificationLayout = new NotificationLayout()
             .setLayoutId(R.layout.custom_notification_layout) // layout layout_id
             .setIconViewId(R.id.iv_notification_icon) // notification icon view_id
             .setIconResourceId(R.drawable.mtpush_notification_icon) // notification icon source_id
             .setTitleViewId(R.id.tv_notification_title) // notification title view_id
             .setContentViewId(R.id.tv_notification_content) // notification content view_id
             .setTimeViewId(R.id.tv_notification_time); // notification time view_id
 
     // Set the custom layout with the build id as BUILDER_ID, and specify builderId as BUILDER_ID when sending the notification to change the layout of the notification
     MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, notificationLayout);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

resetNotificationLayout

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel
/** * Reset custom notification layout, use system notification layout by default * * @param context is not empty * @param builderId id of custom notification layout */ public static void resetNotificationLayout(Context context, int builderId)
               /**
      * Reset custom notification layout, use system notification layout by default
      *
      * @param context is not empty
      * @param builderId id of custom notification layout
      */
     public static void resetNotificationLayout(Context context, int builderId)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Define a constant here, representing the build id private static final int BUILDER_ID = 11; // Reset the custom layout with build id as BUILDER_ID, specify builderId as BUILDER_ID when sending the notification, and use the system default layout MTPushPrivatesApi.resetNotificationLayout(context,BUILDER_ID);
          // Define a constant here, representing the build id
private static final int BUILDER_ID = 11;

     // Reset the custom layout with build id as BUILDER_ID, specify builderId as BUILDER_ID when sending the notification, and use the system default layout
     MTPushPrivatesApi.resetNotificationLayout(context,BUILDER_ID);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setNotificationCount

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel/google channel when the app is in the foreground (shown by Engagelab)
/** * Set the number of notifications in the notification bar, the default number is 5 * * @param context is 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 is 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)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code 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);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

resetNotificationCount

  • Please init first, otherwise the call is invalid
  • Currently supported channels: Engagelab channel/google channel when the app is in the foreground (shown by Engagelab)
/** * Reset the number of notifications in the notification bar, the default number is 5 * * @param context is not empty */ public static void resetNotificationCount(Context context)
               /**
      * Reset the number of notifications in the notification bar, the default number is 5
      *
      * @param context is not empty
      */
     public static void resetNotificationCount(Context context)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code 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);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

setNotificationBadge

  • Please init first, otherwise the call is invalid
/** * Set the number of application badges, the default is 0 (only valid for Huawei/Honor) * * @param context is not empty * @param badge The number of application badges */ public static void setNotificationBadge(Context context, int badge)
               /**
      * Set the number of application badges, the default is 0 (only valid for Huawei/Honor)
      *
      * @param context is not empty
      * @param badge The number of application badges
      */
     public static void setNotificationBadge(Context context, int badge)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Set the number of application badges to 1 MTPushPrivatesApi.setNotificationBadge(context,1);
               // Set the number of application badges to 1
     MTPushPrivatesApi.setNotificationBadge(context,1);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

resetNotificationBadge

  • Please init first, otherwise the call is invalid
/** * Reset the number of application badges, the default is 0 (only valid for Huawei/Honor) * * @param context is not empty */ public static void resetNotificationBadge(Context context) {
               /**
      * Reset the number of application badges, the default is 0 (only valid for Huawei/Honor)
      *
      * @param context is not empty
      */
     public static void resetNotificationBadge(Context context) {

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Reset the number of application badges, the default is 0 MTPushPrivatesApi.resetNotificationBadge(context);
               // Reset the number of application badges, the default is 0
     MTPushPrivatesApi.resetNotificationBadge(context);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

showNotification

  • Please init first, otherwise the call is invalid
/** * Show notification * * @param context is not empty * @param notificationMessage Notification object constructed, not empty */ public static void showNotification(Context context, NotificationMessage notificationMessage)
               /**
      * Show notification
      *
      * @param context is not empty
      * @param notificationMessage Notification object constructed, not empty
      */
     public static void showNotification(Context context, NotificationMessage notificationMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code 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 notification 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 notification
     MTPushPrivatesApi. showNotification(context, notificationMessage);

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

clearNotification

  • Please init first, otherwise the call is invalid
/** * Clear the notification with the specified notifyId * * @param context is not empty * @param notifyId notification id */ public static void clearNotification(Context context, int notifyId)
               /**
      * Clear the notification with the specified notifyId
      *
      * @param context is not empty
      * @param notifyId notification id
      */
     public static void clearNotification(Context context, int notifyId)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

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

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

reportNotificationArrived

  • Please init first, otherwise the call is invalid
  • Does not integrate Engagelab's vendor package, but needs Engagelab to count the notification delivery rate, please call this interface
/** * Report the arrival of the manufacturer channel notification * * Use http/https to report * * @param context is not empty * @param messageId Engagelab message id, not empty * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google) * @param platformMessageId vendor message id, can be empty */ public static void reportNotificationArrived(Context context, String messageId, byte platform, String platformMessageId)
               /**
      * Report the arrival of the manufacturer channel notification
      *
      * Use http/https to report
      *
      * @param context is not empty
      * @param messageId Engagelab message id, not empty
      * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google)
      * @param platformMessageId vendor message id, can be empty
      */
     public static void reportNotificationArrived(Context context, String messageId, byte platform, String platformMessageId)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code 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");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

reportNotificationClicked

  • Please init first, otherwise the call is invalid
  • Does not integrate Engagelab's vendor package, but needs Engagelab to count and notify the click-through rate, please call this interface
/** * Report to the manufacturer channel notification click * * Use http/https to report * * @param context is not empty * @param messageId Engagelab message id, not empty * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google) * @param platformMessageId vendor message id, can be empty */ public static void reportNotificationClicked(Context context, String messageId, byte platform, String platformMessageId)
               /**
      * Report to the manufacturer channel notification click
      *
      * Use http/https to report
      *
      * @param context is not empty
      * @param messageId Engagelab message id, not empty
      * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google)
      * @param platformMessageId vendor message id, can be empty
      */
     public static void reportNotificationClicked(Context context, String messageId, byte platform, String platformMessageId)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Report the manufacturer's notification click, 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");
               // Report the manufacturer's notification click, 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");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

reportNotificationDeleted

  • Please init first, otherwise the call is invalid
  • Does not integrate Engagelab's vendor package, but needs Engagelab to statistically notify deletion rate, please call this interface
/** * Report to the manufacturer channel to notify the deletion * * Use http/https to report * * @param context is not empty * @param messageId Engagelab message id, not empty * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google) * @param platformMessageId vendor message id, can be empty */ public static void reportNotificationDeleted(Context context, String messageId, byte platform, String platformMessageId)
               /**
      * Report to the manufacturer channel to notify the deletion
      *
      * Use http/https to report
      *
      * @param context is not empty
      * @param messageId Engagelab message id, not empty
      * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google)
      * @param platformMessageId vendor message id, can be empty
      */
     public static void reportNotificationDeleted(Context context, String messageId, byte platform, String platformMessageId)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

// Report the manufacturer to delete the notification, the messageId is "12345", the manufacturer is mi, and the manufacturer's messageId is "MI-6476RHT25" MTPushPrivatesApi.reportNotificationDeleted(context,"12345",MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");
               // Report the manufacturer to delete the notification, the messageId is "12345", the manufacturer is mi, and the manufacturer's messageId is "MI-6476RHT25"
     MTPushPrivatesApi.reportNotificationDeleted(context,"12345",MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

reportNotificationOpened

  • Please init first, otherwise the call is invalid
  • Does not integrate Engagelab's vendor package, but needs Engagelab to count the opening rate of notifications, please call this interface
  • Some manufacturers (for example: huawei/oppo/vivo) do not have notification arrival and notification click callbacks. After configuring the activity that the notification clicks to jump, you can get the parameter report in the jump activity. It is recommended that all manufacturers notify the activity that clicks to jump All configured
  • MTPush4.0.0 and above versions do not need
/** * Reporting to the manufacturer channel notification is open * * Use http/https to report * * @param context is not empty * @param messageId Engagelab message id, not empty * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google) * @param platformMessageId vendor message id, can be empty */ public static void reportNotificationOpened(Context context, String messageId, byte platform, String platformMessageId)
               /**
      * Reporting to the manufacturer channel notification is open
      *
      * Use http/https to report
      *
      * @param context is not empty
      * @param messageId Engagelab message id, not empty
      * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google)
      * @param platformMessageId vendor message id, can be empty
      */
     public static void reportNotificationOpened(Context context, String messageId, byte platform, String platformMessageId)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code is as follows

Bundle bundle = intent. getExtras(); String platformMessage = ""; //huawei if (intent. getData() != null) { platformMessage = intent. getData(). toString(); } // other manufacturers if (TextUtils. isEmpty(platformMessage) && intent. getExtras() != null) { if (bundle. containsKey("JMessageExtra")) { platformMessage = bundle. getString("JMessageExtra"); } else { platformMessage = bundle. getString("MTMessageExtra"); } } if (TextUtils. isEmpty(platformMessage)) { return; } JSONObject messageJson = new JSONObject(platformMessage); tvMessage.setText(toLogString(messageJson)); // parse 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"); // Report the notification and click on the activity to open it. It is recommended that all manufacturers jump to add it. It is only required for versions below MTPush4.0.0 MTPushPrivatesApi. reportNotificationOpened(this, messageId, platform, "");
               Bundle bundle = intent. getExtras();
     String platformMessage = "";
     //huawei
     if (intent. getData() != null) {
         platformMessage = intent. getData(). toString();
     }
     // other manufacturers
     if (TextUtils. isEmpty(platformMessage) && intent. getExtras() != null) {
         if (bundle. containsKey("JMessageExtra")) {
              platformMessage = bundle. getString("JMessageExtra");
         } else {
              platformMessage = bundle. getString("MTMessageExtra");
         }
     }
     if (TextUtils. isEmpty(platformMessage)) {
         return;
     }
     JSONObject messageJson = new JSONObject(platformMessage);
     tvMessage.setText(toLogString(messageJson));
     // parse
     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");
     // Report the notification and click on the activity to open it. It is recommended that all manufacturers jump to add it. It is only required for versions below MTPush4.0.0
     MTPushPrivatesApi. reportNotificationOpened(this, messageId, platform, "");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

uploadPlatformToken

  • Please init first, otherwise the call is invalid
  • Due to the tcp upload, the long connection needs to be successful, that is, onConnectStatus calls this interface after the callback result is true
  • Do not integrate Engagelab's vendor packages, but Engagelab is required to push vendor messages
/** * Upload manufacturer token * * Take tcp upload * * @param context is not empty * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google) * @param token The token returned by the manufacturer, not empty * @param region Overseas versions of Xiaomi and Oppo need to set the region. For international versions, fill in: "GLOBAL", and for non-overseas versions, fill in: "NULL" */ public static void uploadPlatformToken(Context context, byte platform, String token, String region)
               /**
      * Upload manufacturer token
      *
      * Take tcp upload
      *
      * @param context is not empty
      * @param platform manufacturer, value range (1:mi, 2:huawei, 3:meizu, 4:oppo, 5:vivo, 7:honor, 8:google)
      * @param token The token returned by the manufacturer, not empty
      * @param region Overseas versions of Xiaomi and Oppo need to set the region. For international versions, fill in: "GLOBAL", and for non-overseas versions, fill in: "NULL"
      */
     public static void uploadPlatformToken(Context context, byte platform, String token, String region)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

The sample code 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","NULL");
               //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","NULL");

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onFragmentResume

  • Please call init first; otherwise, the call will be invalid.
/** * @param context Not null * @param fragmentName Complete class name of the Fragment (this.getClass().getCanonicalName()) */ public static void onFragmentResume(Context context, String fragmentName)
          /**
 * @param context           Not null
 * @param fragmentName      Complete class name of the Fragment (this.getClass().getCanonicalName())
 */
public static void onFragmentResume(Context context, String fragmentName)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onFragmentPause

  • Please call init first; otherwise, the call will be invalid.
/** * @param context Not null * @param fragmentName Complete class name of the Fragment (this.getClass().getCanonicalName()) */ public static void onFragmentPause(Context context, String fragmentName)
          /**
 * @param context           Not null
 * @param fragmentName      Complete class name of the Fragment (this.getClass().getCanonicalName())
 */
public static void onFragmentPause(Context context, String fragmentName)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

Usage Instructions: Since there are four ways to add a Fragment in Android, each method requires different handling of the Fragment. Below are explanations for controlling in-app display for the specified Fragment based on these four methods.

Fragment Usage Method Can It Listen to Fragment Lifecycle? JPush Dynamic Display Page Interface Call Method
Method 1: add/show/hide Cannot listen to lifecycle Call onFragmentResume and onHiddenChanged in the Fragment
Method 2: ViewPager Cannot listen to lifecycle Call setUserVisibleHint in the Fragment
Method 3: replace Can listen to lifecycle Call lifecycle methods onResume and onPause in the Fragment
Method 4: attach/detach Can listen to lifecycle Call lifecycle methods onResume and onPause in the Fragment
  • add/show/hide method

    1) Call the dynamic control interface in the Fragment's onCreateView callback function and pass the required parameters. @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { String classname = this.getClass().getCanonicalName(); JPushInterface.onFragmentResumed(MyApplication.gContext, classname); return inflater.inflate(R.layout.black_fragment, container, false); } 2) Call the dynamic control interface in the Fragment's onHiddenChanged callback and pass the required parameters. @Override public void onHiddenChanged(boolean hidden) { String classname = this.getClass().getCanonicalName(); if (!hidden) { // context should be application context JPushInterface.onFragmentResumed(MyApplication.gContext, classname); } else { // hide JPushInterface.onFragmentPaused(MyApplication.gContext, classname); } super.onHiddenChanged(hidden); }
              1) Call the dynamic control interface in the Fragment's onCreateView callback function and pass the required parameters.
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        String classname = this.getClass().getCanonicalName();
        JPushInterface.onFragmentResumed(MyApplication.gContext, classname);
        return inflater.inflate(R.layout.black_fragment, container, false);
    }  
    
    2) Call the dynamic control interface in the Fragment's onHiddenChanged callback and pass the required parameters.
    
    @Override
    public void onHiddenChanged(boolean hidden) {
        String classname = this.getClass().getCanonicalName();
        if (!hidden) { // context should be application context
            JPushInterface.onFragmentResumed(MyApplication.gContext, classname);
        } else { // hide
            JPushInterface.onFragmentPaused(MyApplication.gContext, classname);  
        } 
        
        super.onHiddenChanged(hidden);
    }  
    
            
    โค้ดนี้โชว์เป็นหน้าต่างลอย
  • ViewPager method

    1) Call the dynamic control interface in the Fragment's setUserVisibleHint callback and pass the required parameters. @Override public void setUserVisibleHint(boolean isVisibleToUser) { String classname = this.getClass().getCanonicalName(); if (isVisibleToUser) { // Pass application context JPushInterface.onFragmentResumed(MyApplication.gContext, classname); } else { // hide JPushInterface.onFragmentPause(MyApplication.gContext, classname); } super.setUserVisibleHint(isVisibleToUser); }
              1) Call the dynamic control interface in the Fragment's setUserVisibleHint callback and pass the required parameters.
    
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        String classname = this.getClass().getCanonicalName();
        if (isVisibleToUser) {
            // Pass application context
            JPushInterface.onFragmentResumed(MyApplication.gContext, classname);
        } else { // hide
            JPushInterface.onFragmentPause(MyApplication.gContext, classname);  
        } 
        
        super.setUserVisibleHint(isVisibleToUser);
    }    
    
            
    โค้ดนี้โชว์เป็นหน้าต่างลอย
  • replace or attach/detach methods

    Call the dynamic page configuration interface in the lifecycle callback of the added Fragment. @Override public void onResume() { // Pass application context String classname = this.getClass().getCanonicalName(); JPushInterface.onFragmentResumed(MyApplication.gContext, classname); super.onResume(); } @Override public void onPause() { String classname = this.getClass().getCanonicalName(); JPushInterface.onFragmentPause(MyApplication.gContext, classname); super.onPause(); }
              Call the dynamic page configuration interface in the lifecycle callback of the added Fragment.
    
    @Override
    public void onResume() { // Pass application context
        String classname = this.getClass().getCanonicalName();
        JPushInterface.onFragmentResumed(MyApplication.gContext, classname);
        super.onResume();
    }
    
    @Override
    public void onPause() {
        String classname = this.getClass().getCanonicalName();
        JPushInterface.onFragmentPause(MyApplication.gContext, classname);  
        super.onPause();
    }
    
            
    โค้ดนี้โชว์เป็นหน้าต่างลอย

MTCommonReceiver

  • is mainly used for method callbacks
  • All method callbacks in this class are in the main process

onNotificationStatus

  • Every time the sdk is started, the current notification switch status will be called back
  • Callback only when there is a change in the follow-up notification switch
/** * Application notification switch state callback * * @param context is not empty * @param enable Whether the notification switch is on, true is on, false is off */ @Override public void onNotificationStatus(Context context, boolean enable)
               /**
      * Application notification switch state callback
      *
      * @param context is not empty
      * @param enable Whether the notification switch is on, true is on, false is off
      */
     @Override
     public void onNotificationStatus(Context context, boolean enable)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onConnectStatus

/** * Whether the long connection is successfully connected * * After initialization, a long connection will be made, and this method will be called back when the connection succeeds or fails * * @param context is not empty * @param enable Whether the long connection is successfully connected, true means success; false means failure */ public void onConnectStatus(Context context, boolean enable)
               /**
      * Whether the long connection is successfully connected
      *
      * After initialization, a long connection will be made, and this method will be called back when the connection succeeds or fails
      *
      * @param context is not empty
      * @param enable Whether the long connection is successfully connected, true means success; false means failure
      */
public void onConnectStatus(Context context, boolean enable)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onNotificationArrived

  • Engagelab/Xiaomi/Meizu channels will have this method callback (the google channel needs to be in the foreground to have a callback)
  • notificationMessage see NotificationMessage for details
/** * Notification message delivered * * This method will be called back when the push notification message is delivered * * @param context is not empty * @param notificationMessage notification message */ public void onNotificationArrived(Context context, NotificationMessage notificationMessage)
               /**
      * Notification message delivered
      *
      * This method will be called back when the push notification message is delivered
      *
      * @param context is not empty
      * @param notificationMessage notification message
      */
     public void onNotificationArrived(Context context, NotificationMessage notificationMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onNotificationUnShow

  • The notification is not displayed in the foreground when the background is sent, and the mobile app calls this method when it is in the foreground.
/** * Notification messages are not displayed in the foreground * * @param context is not empty * @param notificationMessage notification message */ @Override public void onNotificationUnShow(Context context, NotificationMessage notificationMessage)
               /**
      * Notification messages are not displayed in the foreground
      *
      * @param context is not empty
      * @param notificationMessage notification message
      */
     @Override
     public void onNotificationUnShow(Context context, NotificationMessage notificationMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onNotificationClicked

  • Engagelab/Xiaomi/Meizu channels will have this method callback (the google channel needs to be in the foreground to have a callback)
  • notificationMessage see NotificationMessage for details
/** * Notification message click * * Push notification message click will call back this method * * @param context is not empty * @param notificationMessage notification message */ public void onNotificationClicked(Context context, NotificationMessage notificationMessage)
               /**
      * Notification message click
      *
* Push notification message click will call back this method
*
      * @param context is not empty
      * @param notificationMessage notification message
      */
     public void onNotificationClicked(Context context, NotificationMessage notificationMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onNotificationDeleted

  • Only the notification message deletion of the Engagelab channel will trigger
  • notificationMessage see NotificationMessage for details
  • The application cannot be called back when it is in the dead state
/** * Notification message deletion * * Push notification message deletion will call back this method * * @param context is not empty * @param notificationMessage notification message */ public void onNotificationDeleted(Context context, NotificationMessage notificationMessage)
               /**
      * Notification message deletion
      *
* Push notification message deletion will call back this method
*
      * @param context is not empty
      * @param notificationMessage notification message
      */
     public void onNotificationDeleted(Context context, NotificationMessage notificationMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onCustomMessage

  • Custom messages will not be displayed in the notification bar
  • Only the notification message deletion of the Engagelab channel will trigger
  • customMessage see CustomMessage for details
/** * Custom message delivery * * This method will be called back when the custom message is delivered * * @param context is not empty * @param customMessage custom message */ public void onCustomMessage(Context context, CustomMessage customMessage)
               /**
      * Custom message delivery
      *
      * This method will be called back when the custom message is delivered
      *
      * @param context is not empty
      * @param customMessage custom message
      */
     public void onCustomMessage(Context context, CustomMessage customMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onTagMessage

/** * tag operation message * * @param context is not empty * @param tagMessage tag information */ public void onTagMessage(Context context, TagMessage tagMessage)
               /**
      * tag operation message
      *
      * @param context is not empty
      * @param tagMessage tag information
      */
     public void onTagMessage(Context context, TagMessage tagMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onAliasMessage

/** * alias operation message * * @param context ApplicationContext object * @param aliasMessage alias message */ public void onAliasMessage(Context context, AliasMessage aliasMessage)
               /**
      * alias operation message
      *
      * @param context ApplicationContext object
      * @param aliasMessage alias message
      */
     public void onAliasMessage(Context context, AliasMessage aliasMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onPlatformToken

  • Manufacturer token message callback
/** * Manufacturer operation message * * @param context ApplicationContext object * @param platformMessage Manufacturer token message */ public void onPlatformToken(Context context, PlatformTokenMessage platformMessage)
              /**
     * Manufacturer operation message
     *
     * @param context         ApplicationContext object
     * @param platformMessage Manufacturer token message
     */
    public void onPlatformToken(Context context, PlatformTokenMessage platformMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onInAppMessageShow

  • In-app message display callback
/** * * * @param context ApplicationContext object * @param inAppMessage In-app message */ public void onInAppMessageShow(Context context, InAppMessage inAppMessage)
          /**
 * 
 *
 * @param context         ApplicationContext object
 * @param inAppMessage    In-app message
 */
public void onInAppMessageShow(Context context, InAppMessage inAppMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

onInAppMessageClick

  • In-app message click callback
/** * * * @param context ApplicationContext object * @param inAppMessage In-app message */ public void onInAppMessageClick(Context context, InAppMessage inAppMessage)
          /**
 * 
 *
 * @param context         ApplicationContext object
 * @param inAppMessage    In-app message
 */
public void onInAppMessageClick(Context context, InAppMessage inAppMessage)

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

NotificationChannel Configuration

Supported Versions

Supported starting from version: MTPush SDK v3.3.0

Feature Description

After Android 8.0, notifications are managed through NotificationChannels. Developers can define their own NotificationChannels, and then specify the channelId for notifications when pushing via API; On devices running Android 8.0 or later, the notification will first search for the channel corresponding to the specified channelId, with the notification's importance level, sound, vibration, and LED determined by the channel; If the channelId is not found, or it is within a silent period, it will default to the engagelab channel.

Custom NotificationChannel Example

private void initChannel(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (nm != null){ NotificationChannelGroup notificationChannelGroup = new NotificationChannelGroup("MyGroupId", "Custom Notification Group"); nm.createNotificationChannelGroup(notificationChannelGroup); NotificationChannel notificationChannel = new NotificationChannel("MyChannelId", "Custom Notification", NotificationManager.IMPORTANCE_HIGH); notificationChannel.setGroup("MyGroupId"); notificationChannel.enableLights(true); notificationChannel.enableVibration(true); notificationChannel.setSound("android.resource:// package_name /raw/ ringtone_file", null); // Set custom ringtone nm.createNotificationChannel(notificationChannel); } } }
              private void initChannel(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            if (nm != null){ NotificationChannelGroup notificationChannelGroup = new NotificationChannelGroup("MyGroupId", "Custom Notification Group");
                nm.createNotificationChannelGroup(notificationChannelGroup);

                NotificationChannel notificationChannel = new NotificationChannel("MyChannelId", "Custom Notification", NotificationManager.IMPORTANCE_HIGH);
                notificationChannel.setGroup("MyGroupId");
                notificationChannel.enableLights(true);
                notificationChannel.enableVibration(true);
                notificationChannel.setSound("android.resource:// package_name /raw/ ringtone_file", null); // Set custom ringtone

                nm.createNotificationChannel(notificationChannel);
            }
        }
    }

        
โค้ดนี้โชว์เป็นหน้าต่างลอย

NotificationMessage

  • Notification Message
Attribute Type Description
messageId String Required. Engagelab messageId used for message tracking and statistics. Cannot be empty. If empty, the notification will not be displayed.
overrideMessageId String Engagelab overrideMessageId used for message tracking and statistics.
platform byte Manufacturer type. Default is 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
Honor: MTPushPrivatesApi.PLATFORM_HONOR: 7
Google: MTPushPrivatesApi.PLATFORM_GOOGLE: 8
platformMessageId String Manufacturer messageId used for manufacturer message tracking and statistics.
notificationId int Notification ID. Can be used to cancel the notification by calling clearNotification.
smallIcon String Small icon. Default value: drawable/mtpush_notification_icon.png.
largeIcon String Large icon, usually displayed on the right side of the notification.
title String Notification title. If empty, the app name will be used.
content String Required. Notification content. Cannot be empty. If empty, the notification will not be displayed.
extras Bundle Additional fields in key/value format, both as String.
builderId int Notification style ID. Can be set using setNotificationLayout. Default value: system style.
style int Notification style. Default value: 0
Big text style (NOTIFICATION_STYLE_BIG_TEXT): 1
Inbox style (NOTIFICATION_STYLE_INBOX): 2
Big picture style (NOTIFICATION_STYLE_BIG_PICTURE): 3
bigText String Big text. Effective when style is NOTIFICATION_STYLE_BIG_TEXT.
inbox String[] Inbox. Effective when style is NOTIFICATION_STYLE_INBOX.
bigPicture String Big picture. Effective when style is NOTIFICATION_STYLE_BIG_PICTURE.
priority int Notification priority. Default value: 0
Low priority, notification has no LED, vibration, and sound (Notification.PRIORITY_LOW: -1)
Normal priority, notification can have LED, vibration, and sound (Notification.PRIORITY_DEFAULT: 0)
High priority, notification can have LED, vibration, sound, and can pop up as a floating window (Notification.PRIORITY_HIGH: 1)
defaults int Default values for sound, vibration, and LED. Default value: Notification.DEFAULT_ALL: -1
Sound: Notification.DEFAULT_SOUND: 1
Vibration: Notification.DEFAULT_VIBRATE: 2
LED: Notification.DEFAULT_LIGHTS: 4
These values can be combined. For example, 7 represents sound, vibration, and LED.
From Android 8.0, this property follows the channel settings.
category String Notification category, used for sorting or filtering in the notification bar.
There are various categories, similar to Notification.CATEGORY_ALARM, Notification#CATEGORY_CALL, etc.
sound String Sound file attached to the notification. The sound file needs to exist in the res/raw directory in advance.
From Android 8.0, the sound follows the channel. If the channel used by the notification does not have a sound set, the custom sound will not take effect.
It is recommended to set the sound in the channel in advance, and keep the sound consistent between subsequent notifications and the sound in the channelId to maintain consistency of notification sound effects.
channelId String Required from Android 8.0. If not set in advance, the SDK will help set it (only for Engagelab channel and Google channel when the app is in the foreground).
intentUri String Intent URI for the click action after the notification is clicked. Currently only supports activity. Convert the activity jump using Intent.toURI().
badge int Number of badges added by this notification. It accumulates, and the value needs to be greater than 0. Recommended to set as 1.
Only applicable to Huawei and Xiaomi.
For Xiaomi, the badge number will automatically decrease by 1 after clicking the notification.
For Huawei, the badge number will not automatically decrease by 1 after clicking the notification. It is recommended to use setNotificationBadge to set.

CustomMessage

  • Custom Message
Attribute Type Description
messageId String Required. Engagelab messageId used for message tracking and statistics. Cannot be empty.
platform byte Manufacturer type. Default is 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
Honor: MTPushPrivatesApi.PLATFORM_HONOR: 7
Google: MTPushPrivatesApi.PLATFORM_GOOGLE: 8
platformMessageId String Manufacturer messageId used for manufacturer message tracking and statistics.
title String Message title.
content String Message content.
contentType String Message type.
extras Bundle Additional fields in key/value format, both as String.

TagMessage

  • Tag Message
Attribute Type Description
sequence int User-defined operation sequence number. It is returned along with the operation result to identify the uniqueness of the operation.
code int Operation result. For details, please refer to code.
tags String[] Array of tags. The following operations will return:
addTag
deleteTag
updateTag
queryAllTag
queryTag String Tag. The following operation will return:
queryTag
queryTagValid boolean Tag status. The following operation will return:
queryTag

AliasMessage

  • Alias Message
Attribute Type Description
sequence int User-defined operation sequence number. It is returned along with the operation result to identify the uniqueness of the operation.
code int Operation result. For details, please refer to code.
alias String Alias. The following operations will return:
setAlias
getAlias

PlatformTokenMessage

  • Platform Token Message
Attribute Type Description
platform byte Manufacturer type. Default is 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
Honor: MTPushPrivatesApi.PLATFORM_HONOR: 7
Google: MTPushPrivatesApi.PLATFORM_GOOGLE: 8
token String Token returned by the manufacturer.

InAppMessage

  • In-app message
Attribute Type Description
messageId String Required. Engagelab messageId, used for message tracking and statistics. Cannot be empty; if empty, the message will not be displayed.
overrideMessageId String Engagelab overrideMessageId, used for message tracking and statistics.
target String Target page paths for displaying in-app messages.
imageUrl String URL of the in-app message image.
extras String Additional information for pass-through.
content String Specific content of the in-app message.
expired long Expiration time.
delay long Delay time for displaying the message.
interval long Interval time for displaying in-app messages.
duration long Display duration of the in-app message.
msgTime long Time when the SDK received the in-app message.

code

code int value description
SUCCESS 0 Success
NULL_TAG_AND_ALIAS 6001 Invalid setting
TIMEOUT 6002 Set a timeout; it is recommended to try again, usually when the network is not good and the initialization has not been completed
INVALID_ALIAS 6003 The alias string is invalid. Valid aliases and labels consist of: letters (case-sensitive), numbers, underscores, Chinese characters, special characters (supported by 2.1.6) @!#$&*+=.\
TOO_LONG_ALIAS 6004 The alias is too long. Up to 40 bytes, Chinese UTF-8 is 3 bytes
INVALID_TAGS 6005 A certain tag string is invalid. Valid aliases and tags consist of: letters (case-sensitive), numbers, underscores, Chinese characters, special characters (supported by 2.1.6) @!#$&*+=.\
TOO_LONG_TAG 6006 A certain tag is too long. A tag can be up to 40 bytes, and Chinese UTF-8 is 3 bytes
TOO_MANY_TAGS 6007 The number of tags exceeds the limit. Up to 1000, which is the limit of one device. There is no limit to the number of tags globally for an application.
TOO_LONG_TAGS 6008 The length of a single tag operation exceeds 5000
UNKNOWN_ERROR 6009 Unknown error
INVALID_JSON 6010 Invalid json
INVOKE_TOO_SOON 6012 Frequent tag/alias operations
CONNECT_NOT_ENABLE 6013 CONNECT_NOT_ENABLE
在文档中心打开
icon
ติดต่อฝ่ายขาย