SDK API

最新更新:2024-02-22

MTCorePrivatesApi

  • 主要用於信息配置
  • 所有方法都需要在主進程中調用,請不要在方法調用前判斷進程將其放到子進程,否則調用出錯

設置心跳時間間隔

  • 需要在 Application.onCreate() 方法中調用
  • 請在 init 之前調用
/** * 設置心跳時間間隔 * * 需要在 Application.onCreate() 方法中調用 * * @param context 不為空 * @param heartbeatInterval 時間單位為毫秒、必須大於 0、默認值是 4 分 50 秒 \ */ public static void configHeartbeatInterval(Context context, long heartbeatInterval)
              /**
     * 設置心跳時間間隔
     *
     * 需要在 Application.onCreate() 方法中調用
     *
     * @param context 不為空
     * @param heartbeatInterval 時間單位為毫秒、必須大於 0、默認值是 4 分 50 秒 \
     */
    public static void configHeartbeatInterval(Context context, long heartbeatInterval)

        
此代碼塊在浮窗中顯示

示例代碼如下:

  • 演示設置心跳時間間隔為 3 分鐘
MTCorePrivatesApi.configHeartbeatInterval(this,3 * 60 * 1000);
          MTCorePrivatesApi.configHeartbeatInterval(this,3 * 60 * 1000);

        
此代碼塊在浮窗中顯示

設置長連接重試次數

  • 需要在 Application.onCreate() 方法中調用
  • 請在 init 之前調用
/** * 設置長連接重試次數 * * 需要在 Application.onCreate() 方法中調用 * * @param context 不為空 * @param connectRetryCount 重試的次數、默認值為 3、最少 3 次 */ public static void configConnectRetryCount(Context context, int connectRetryCount)
              /**
     * 設置長連接重試次數
     *
     * 需要在 Application.onCreate() 方法中調用
     *
     * @param context 不為空
     * @param connectRetryCount 重試的次數、默認值為 3、最少 3 次
     */
    public static void configConnectRetryCount(Context context, int connectRetryCount)

        
此代碼塊在浮窗中顯示

示例代碼如下:

演示設置重連次數為 10 次

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

        
此代碼塊在浮窗中顯示

setTcpSSl

  • 需要在Application.onCreate()方法中调用
  • 请在init之前调用
/** * 设置长连接是否加密,默认不加密 * * 需要在Application.onCreate()方法中调用 * * @param isSSL true加密,false不加密 */ public static void setTcpSSl(Context context, boolean isSSL)
              /**
     * 设置长连接是否加密,默认不加密
     *
     * 需要在Application.onCreate()方法中调用
     *
     * @param isSSL true加密,false不加密
     */
    public static void setTcpSSl(Context context, boolean isSSL)

        
此代碼塊在浮窗中顯示

代码示例如下

*演示设置加密

MTCorePrivatesApi.setTcpSSl(context,true);
          MTCorePrivatesApi.setTcpSSl(context,true);

        
此代碼塊在浮窗中顯示

設置調試模式

  • 需要在 Application.onCreate() 方法中調用
  • 請在 init 之前調用
  • 私有云 Engagelab 日誌格式,搜索 "ENGAGELAB-PRIVATES"
  • 私有云 Engagelab 會分別在主進程和子進程打印日誌
/** * 設置是否 debug 模式,debug 模式會打印更對詳細日誌 * * 需要在 Application.onCreate() 方法中調用 * * @param context 不為空 * @param enable 是否調試模式,true 為調試模式,false 不是 */ public static void configDebugMode(Context context, boolean enable)
              /**
     * 設置是否 debug 模式,debug 模式會打印更對詳細日誌
     *
     * 需要在 Application.onCreate() 方法中調用
     * 
     * @param context 不為空 
     * @param enable 是否調試模式,true 為調試模式,false 不是
     */
    public static void configDebugMode(Context context, boolean enable)

        
此代碼塊在浮窗中顯示

示例代碼如下:

  • sdk 在兩個進程工作,主進程和子進程,子進程名為 MTCommonService 子類 service 的 process 屬性名
  • 私有云 sdk 的日誌 tag 為 "ENGAGELAB-PRIVATES"
  • udp/tcp/http 相關操作的日誌均在子進程
  • 所以遇到訊息無法推播的情況,請先打開調試模式,再前往子進程獲取 tag 為 "ENGAGELAB-PRIVATES" 的日誌,提供給技術支持分析
// 建議應用程式未上線時設置為 true,方便集成 MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // 建議應用程式上線後設置為 false MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), false);
                  // 建議應用程式未上線時設置為 true,方便集成
        MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true);
        
        // 建議應用程式上線後設置為 false
        MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), false);

        
此代碼塊在浮窗中顯示

設置國密加密

  • 需要在 Application.onCreate() 方法中調用
  • 請在 init 之前調用
/** * 配置使用國密加密 * * @param context 不為空 */ public static void configSM4(Context context)
              /**
     * 配置使用國密加密
     *
     * @param context 不為空
     */
    public static void configSM4(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 開啟國密加密,不調用則使用默認加密方式 MTCorePrivatesApi.configSM4(context.getApplicationContext());
              // 開啟國密加密,不調用則使用默認加密方式
    MTCorePrivatesApi.configSM4(context.getApplicationContext());

        
此代碼塊在浮窗中顯示

獲取 UserId

  • 返回值為空時需要注意是否配置了環境,是否調用了初始化
  • 如果檢查配置無誤,可能還在連接過程中,可在 onConnectStatus 返回 true 時再獲取
/** * 獲取當前設備的 userId,Engagelab 私有云唯一標識,可同於推播 * * @param context 不為空 * @return userId */ public static String getUserId(Context context)
              /**
     * 獲取當前設備的 userId,Engagelab 私有云唯一標識,可同於推播
     *
     * @param context 不為空
     * @return userId
     */
    public static String getUserId(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

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

        
此代碼塊在浮窗中顯示

獲取 RegistrationId

  • 返回值為空時需要注意是否配置了環境,是否調用了初始化
  • 如果檢查配置無誤,可能還在連接過程中,可在 onConnectStatus 返回 true 時再獲取
/** * 獲取當前設備的 registrationId,Engagelab 私有云唯一標識,可同於推播 * * @param context 不為空 * @return registrationId */ public static String getRegistrationId(Context context)
              /**
     * 獲取當前設備的 registrationId,Engagelab 私有云唯一標識,可同於推播
     *
     * @param context 不為空
     * @return registrationId
     */
    public static String getRegistrationId(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

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

        
此代碼塊在浮窗中顯示

MTPushPrivatesApi 類

  • 主要用於推播功能
  • 所有方法都需要在主進程中調用,請不要在方法調用前判斷進程將其放到子進程,否則調用出錯

設置版本號

  • 後台沒升級 tag: V3.5.4-newportal-20210823-gamma.57 版本,前端必須調用此方法,否則通知點擊跳轉有問題
  • 在 Application.onCreate() 方法中調用
  • 請在 init 前調用
/** * 配置 push 版本號為 3.9.X * * @param context 不為空 */ public static void configOldPushVersion(Context context)
              /**
     * 配置 push 版本號為 3.9.X
     *
     * @param context 不為空
     */
    public static void configOldPushVersion(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

public class ExampleApplication extends Application { @Override public void onCreate() { // 打開調試模式 MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // 使用老版本的通知點擊跳轉 MTPushPrivatesApi.configOldPushVersion(context.getApplicationContext()); // 初始化 MTPushPrivatesApi.init(context.getApplicationContext()); } }
          public class ExampleApplication extends Application {

    @Override
    public void onCreate() {
        // 打開調試模式    
            MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true);
            // 使用老版本的通知點擊跳轉
            MTPushPrivatesApi.configOldPushVersion(context.getApplicationContext());
            // 初始化
                MTPushPrivatesApi.init(context.getApplicationContext());   
    }
}

        
此代碼塊在浮窗中顯示

初始化

  • 建議在 Application.onCreate() 方法中調用
/** * MTPush 初始化 * * 建議在 Application.onCreate() 方法中調用 * * @param context 不為空,請使用 applicationContext 對象 */ public static void init(Context context)
              /**
     * MTPush 初始化
     *
     * 建議在 Application.onCreate() 方法中調用
     * 
     * @param context 不為空,請使用 applicationContext 對象
     */
    public static void init(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

public class ExampleApplication extends Application { @Override public void onCreate() { // 打開調試模式 MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true); // 初始化 MTPushPrivatesApi.init(context.getApplicationContext()); } }
          public class ExampleApplication extends Application {

    @Override
    public void onCreate() {
        // 打開調試模式    
            MTCorePrivatesApi.configDebugMode(context.getApplicationContext(), true);
            // 初始化
                MTPushPrivatesApi.init(context.getApplicationContext());   
    }
}

        
此代碼塊在浮窗中顯示

跳轉至通知開關設置頁面

/** * 前往通知開關設置頁面 * * @param context 不為空 */ public static void goToAppNotificationSettings(Context context)
              /**
     * 前往通知開關設置頁面
     *
     * @param context 不為空
     */
    public static void goToAppNotificationSettings(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 前往通知開關設置頁面,需要客戶手動打開通知開關 MTPushPrivatesApi.goToAppNotificationSettings(this); // 繼承 MTCommonReceiver 後,複寫 onNotificationStatus 方法,獲取通知開關狀態,如果 enable 為 true 說明已經開啟成功 @Override public void onNotificationStatus(Context context, boolean enable) {if(enable){// 已設置通知開關為打開} }
              // 前往通知開關設置頁面,需要客戶手動打開通知開關
    MTPushPrivatesApi.goToAppNotificationSettings(this);
    
    // 繼承 MTCommonReceiver 後,複寫 onNotificationStatus 方法,獲取通知開關狀態,如果 enable 為 true 說明已經開啟成功
    @Override
    public void onNotificationStatus(Context context, boolean enable) {if(enable){// 已設置通知開關為打開}	    
    }

        
此代碼塊在浮窗中顯示

開啟推播服務

  • 一般用於在調用 turnOffPush 後,需要再開啟 push 推播
  • 重複調用只會生效一次,如果已經是開啟狀態,不會再生效
  • 如果環境沒有問題,onConnectStatus 會回調結果
  • 目前支持的通道:Engagelab/ 華為 / 小米 / 魅族 /oppo/vivo
/** * 開啟 Push 推播,並持久化存儲開關狀態為 true,默認是 true * * @param context 不能為空 */ public static void turnOnPush(Context context)
              /**
     * 開啟 Push 推播,並持久化存儲開關狀態為 true,默認是 true
     * 
     * @param context 不能為空
     */
    public static void turnOnPush(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 開啟推播,默認就是打開的 MTPushPrivatesApi.turnOnPush(context); // 繼承 MTCommonReceiver 後,複寫 onConnectStatus 方法,獲取長連接的連接狀態,如果 enable 為 true 說明已經開啟成功 @Override public void onConnectStatus(Context context, boolean enable){if(enable){// 開啟 push 推播成功} }
                  // 開啟推播,默認就是打開的
        MTPushPrivatesApi.turnOnPush(context);
        
        // 繼承 MTCommonReceiver 後,複寫 onConnectStatus 方法,獲取長連接的連接狀態,如果 enable 為 true 說明已經開啟成功
        @Override
        public void onConnectStatus(Context context, boolean enable){if(enable){// 開啟 push 推播成功}				
        }

        
此代碼塊在浮窗中顯示

關閉推播服務

  • 一般用於關閉 push 推播
  • 關閉 push 推播後,再調用 init 不會打開推播
  • 重複調用只會生效一次
  • 如果環境沒有問題,onConnectStatus 會回調結果
  • 目前支持的通道:Engagelab/ 華為 / 小米 / 魅族 /oppo/vivo
/** * 關閉 push 推播,並持久化存儲開關狀態為 false,默認是 true * * @param context 不能為空 */ public static void turnOffPush(Context context)
              /**
     * 關閉 push 推播,並持久化存儲開關狀態為 false,默認是 true
     *
     * @param context 不能為空
     */
    public static void turnOffPush(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 關閉推播,需要再調用 turnOnPush 才能開啟推播 MTPushPrivatesApi.turnOffPush(context); // 繼承 MTCommonReceiver 後,複寫 onConnectStatus 方法,獲取長連接狀態,如果 enable 為 false 說明已經關閉成功 @Override public void onConnectStatus(Context context, boolean enable){if(!enable){// 關閉 push 推播成功} }
                  // 關閉推播,需要再調用 turnOnPush 才能開啟推播
        MTPushPrivatesApi.turnOffPush(context);
        
        // 繼承 MTCommonReceiver 後,複寫 onConnectStatus 方法,獲取長連接狀態,如果 enable 為 false 說明已經關閉成功
        @Override
        public void onConnectStatus(Context context, boolean enable){if(!enable){// 關閉 push 推播成功}
        }

        
此代碼塊在浮窗中顯示

設置通知展示時間

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道 / 應用程式在前台時的 google 通道(由 Engagelab 展示)
/** * 設置通知展示時間,默認任何時間都展示 * * @param context 不為空 * @param beginHour 允許通知展示的開始時間( 24 小時制,範圍為 0 到 23 ) * @param endHour 允許通知展示的結束時間( 24 小時制,範圍為 0 到 23 ),beginHour 不能大於等於 endHour * @param weekDays 允許通知展示的星期數組( 7 日制,範圍為 1 到 7),空數組代表任何時候都不展示通知 */ public static void setNotificationShowTime(Context context, int beginHour, int endHour, int... weekDays)
              /**
     * 設置通知展示時間,默認任何時間都展示
     *
     * @param context   不為空
     * @param beginHour 允許通知展示的開始時間( 24 小時制,範圍為 0 到 23 )
     * @param endHour   允許通知展示的結束時間( 24 小時制,範圍為 0 到 23 ),beginHour 不能大於等於 endHour
     * @param weekDays  允許通知展示的星期數組( 7 日制,範圍為 1 到 7),空數組代表任何時候都不展示通知
     */
    public static void setNotificationShowTime(Context context, int beginHour, int endHour, int... weekDays)

        
此代碼塊在浮窗中顯示

示例代碼如下

// 設置通知展示時間為每週 1/3/5/7 的早上 9 點到晚上 9 點 MTPushPrivatesApi.setNotificationShowTime(context, 9, 21, 1,3,5,7);
              // 設置通知展示時間為每週 1/3/5/7 的早上 9 點到晚上 9 點
    MTPushPrivatesApi.setNotificationShowTime(context, 9, 21, 1,3,5,7);

        
此代碼塊在浮窗中顯示

重置通知展示時間

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道 / 應用程式在前台時的 google 通道(由 Engagelab 展示)
/** * 重置通知展示時間,默認任何時間都展示 * * @param context 不為空 */ public static void resetNotificationShowTime(Context context)
              /**
     * 重置通知展示時間,默認任何時間都展示
     *
     * @param context 不為空
     */
    public static void resetNotificationShowTime(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 重置通知展示時間,默認任何時間都展示 MTPushPrivatesApi.resetNotificationShowTime(context);
              // 重置通知展示時間,默認任何時間都展示
    MTPushPrivatesApi.resetNotificationShowTime(context);

        
此代碼塊在浮窗中顯示

設置通知靜默時間

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道 / 應用程式在前台時的 google 通道(由 Engagelab 展示)
/** * 設置通知靜默時間,默認任何時間都不靜默 * * @param context 不為空 * @param beginHour 允許通知靜默的開始時間,單位小時( 24 小時制,範圍為 0 到 23 ) * @param beginMinute 允許通知靜默的開始時間,單位分鐘( 60 分鐘制,範圍為 0 到 59 ) * @param endHour 允許通知靜默的結束時間,單位小時( 24 小時制,範圍為 0 到 23 ) * @param endMinute 允許通知靜默的結束時間,單位分鐘( 60 分鐘制,範圍為 0 到 59 ) */ public static void setNotificationSilenceTime(Context context, int beginHour, int beginMinute, int endHour, int endMinute)
              /**
     * 設置通知靜默時間,默認任何時間都不靜默
     *
     * @param context     不為空
     * @param beginHour   允許通知靜默的開始時間,單位小時( 24 小時制,範圍為 0 到 23 )
     * @param beginMinute 允許通知靜默的開始時間,單位分鐘( 60 分鐘制,範圍為 0 到 59 )
     * @param endHour     允許通知靜默的結束時間,單位小時( 24 小時制,範圍為 0 到 23 )
     * @param endMinute   允許通知靜默的結束時間,單位分鐘( 60 分鐘制,範圍為 0 到 59 )
     */
    public static void setNotificationSilenceTime(Context context, int beginHour, int beginMinute, int endHour, int endMinute)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 設置通知靜默時間為每天晚上 9 點半到第二天早上 9 點半 MTPushPrivatesApi.setNotificationSilenceTime(context, 21, 30, 9, 30);
              // 設置通知靜默時間為每天晚上 9 點半到第二天早上 9 點半
    MTPushPrivatesApi.setNotificationSilenceTime(context, 21, 30, 9, 30);

        
此代碼塊在浮窗中顯示

重置通知靜默時間

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道 / 應用程式在前台時的 google 通道(由 Engagelab 展示)
/** * 重置通知靜默時間,默認任何時間都不靜默 * * @param context 不為空 */ public static void resetNotificationSilenceTime(Context context)
              /**
     * 重置通知靜默時間,默認任何時間都不靜默
     *
     * @param context 不為空
     */
    public static void resetNotificationSilenceTime(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下

// 重置通知靜默時間,默認任何時間都不靜默 MTPushPrivatesApi.resetNotificationSilenceTime(context);
              // 重置通知靜默時間,默認任何時間都不靜默
    MTPushPrivatesApi.resetNotificationSilenceTime(context);

        
此代碼塊在浮窗中顯示

設置自訂通知佈局

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道
/** * 設置自訂通知佈局,默認使用系統通知佈局 * * @param context 不為空 * @param builderId 構建 id * @param notificationLayout 自訂通知佈局的對象,不為空 */ public static void setNotificationLayout(Context context, int builderId, NotificationLayout notificationLayout)
              /**
     * 設置自訂通知佈局,默認使用系統通知佈局
     *
     * @param context            不為空
     * @param builderId          構建 id
     * @param notificationLayout 自訂通知佈局的對象,不為空
     */
    public static void setNotificationLayout(Context context, int builderId, NotificationLayout notificationLayout)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 這裡定義一個常量,代表構建 id private static final int BUILDER_ID = 11; // 構建出一個 notificationLayout NotificationLayout notificationLayout = new NotificationLayout().setLayoutId(R.layout.custom_notification_layout) // 佈局 layout_id .setIconViewId(R.id.iv_notification_icon) // 通知圖標 view_id .setIconResourceId(R.drawable.mtpush_notification_icon) // 通知圖標 source_id .setTitleViewId(R.id.tv_notification_title) // 通知標題 view_id .setContentViewId(R.id.tv_notification_content) // 通知內容 view_id .setTimeViewId(R.id.tv_notification_time); // 通知時間 view_id // 設置構建 id 為 BUILDER_ID 的自訂佈局,傳送通知時指定 builderId 為 BUILDER_ID,即可改變通知佈局 MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, notificationLayout);
                  // 這裡定義一個常量,代表構建 id
        private static final int BUILDER_ID = 11;
        
        // 構建出一個 notificationLayout
    NotificationLayout notificationLayout = new NotificationLayout().setLayoutId(R.layout.custom_notification_layout)        // 佈局 layout_id
            .setIconViewId(R.id.iv_notification_icon)                // 通知圖標 view_id
            .setIconResourceId(R.drawable.mtpush_notification_icon)   // 通知圖標 source_id
            .setTitleViewId(R.id.tv_notification_title)              // 通知標題 view_id
            .setContentViewId(R.id.tv_notification_content)          // 通知內容 view_id
            .setTimeViewId(R.id.tv_notification_time);               // 通知時間 view_id
 
    // 設置構建 id 為 BUILDER_ID 的自訂佈局,傳送通知時指定 builderId 為 BUILDER_ID,即可改變通知佈局        
    MTPushPrivatesApi.setNotificationLayout(this.getApplicationContext(), BUILDER_ID, notificationLayout);

        
此代碼塊在浮窗中顯示

重置自訂通知佈局

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道
/** * 重置自訂通知佈局,默認使用系統通知佈局 * * @param context 不為空 * @param builderId 自訂通知佈局的 id */ public static void resetNotificationLayout(Context context, int builderId)
              /**
     * 重置自訂通知佈局,默認使用系統通知佈局
     *
     * @param context   不為空
     * @param builderId 自訂通知佈局的 id
     */
    public static void resetNotificationLayout(Context context, int builderId)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 這裡定義一個常量,代表構建 id private static final int BUILDER_ID = 11; // 重置構建 id 為 BUILDER_ID 的自訂佈局,傳送通知時指定 builderId 為 BUILDER_ID,將使用系統默認佈局 MTPushPrivatesApi.resetNotificationLayout(context,BUILDER_ID);
                  // 這裡定義一個常量,代表構建 id
        private static final int BUILDER_ID = 11;
        
    // 重置構建 id 為 BUILDER_ID 的自訂佈局,傳送通知時指定 builderId 為 BUILDER_ID,將使用系統默認佈局
    MTPushPrivatesApi.resetNotificationLayout(context,BUILDER_ID);

        
此代碼塊在浮窗中顯示

設置通知欄的通知數量

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道 / 應用程式在前台時的 google 通道(由 Engagelab 展示)
/** * 設置通知欄的通知數量,默認數量為 5 * * @param context 不為空 * @param count 限制通知欄的通知數量,超出限制數量則移除最老通知,不能小於等於 0 */ public static void setNotificationCount(Context context, int count)
              /**
     * 設置通知欄的通知數量,默認數量為 5
     *
     * @param context 不為空
     * @param count   限制通知欄的通知數量,超出限制數量則移除最老通知,不能小於等於 0
     */
    public static void setNotificationCount(Context context, int count)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 設置通知欄通知數量為 50 MTPushPrivatesApi.setNotificationCount(context,50);
              // 設置通知欄通知數量為 50
    MTPushPrivatesApi.setNotificationCount(context,50);

        
此代碼塊在浮窗中顯示

重置通知欄的通知數量

  • 請先 init,否則調用無效
  • 目前支持的通道:Engagelab 通道 / 應用程式在前台時的 google 通道(由 Engagelab 展示)
/** * 重置通知欄的通知數量,默認數量為 5 * * @param context 不為空 */ public static void resetNotificationCount(Context context)
              /**
     * 重置通知欄的通知數量,默認數量為 5
     *
     * @param context 不為空
     */
    public static void resetNotificationCount(Context context)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 重置通知欄的通知數量,默認數量為 5 MTPushPrivatesApi.resetNotificationCount(context);
              // 重置通知欄的通知數量,默認數量為 5
    MTPushPrivatesApi.resetNotificationCount(context);

        
此代碼塊在浮窗中顯示

設置應用程式角標

  • 請先 init,否則調用無效
/** * 設置應用程式角標數量,默認 0(僅華為 / 榮耀生效) * * @param context 不為空 * @param badge 應用程式角標數量 */ public static void setNotificationBadge(Context context, int badge)
              /**
     * 設置應用程式角標數量,默認 0(僅華為 / 榮耀生效)
     *
     * @param context 不為空
     * @param badge   應用程式角標數量
     */
    public static void setNotificationBadge(Context context, int badge)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 設置應用程式角標數量為 1 MTPushPrivatesApi.setNotificationBadge(context,1);
              // 設置應用程式角標數量為 1
    MTPushPrivatesApi.setNotificationBadge(context,1);

        
此代碼塊在浮窗中顯示

重置應用程式角標

  • 請先 init,否則調用無效
/** * 重置應用程式角標數量,默認 0(僅華為 / 榮耀生效) * * @param context 不為空 */ public static void resetNotificationBadge(Context context) {
              /**
     * 重置應用程式角標數量,默認 0(僅華為 / 榮耀生效)
     *
     * @param context 不為空
     */
    public static void resetNotificationBadge(Context context) {

        
此代碼塊在浮窗中顯示

示例代碼如下

// 重置應用程式角標數量,默認 0 MTPushPrivatesApi.resetNotificationBadge(context);
              // 重置應用程式角標數量,默認 0
    MTPushPrivatesApi.resetNotificationBadge(context);

        
此代碼塊在浮窗中顯示

展示通知

  • 請先 init,否則調用無效
/** * 展示通知 * * @param context 不為空 * @param notificationMessage 構建的通知對象,不為空 */ public static void showNotification(Context context, NotificationMessage notificationMessage)
              /**
     * 展示通知
     *
     * @param context             不為空
     * @param notificationMessage 構建的通知對象,不為空
     */
    public static void showNotification(Context context, NotificationMessage notificationMessage)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 構建一個基礎的通知,其中 messageId 和 content 是必須,否則通知無法展示 NotificationMessage notificationMessage = new NotificationMessage().setMessageId("12345") .setNotificationId(12345) .setTitle("custom_notification_title") .setContent("custom_notification_content"); // 展示通知 MTPushPrivatesApi.showNotification(context,notificationMessage);
              // 構建一個基礎的通知,其中 messageId 和 content 是必須,否則通知無法展示
    NotificationMessage notificationMessage = new NotificationMessage().setMessageId("12345")
            .setNotificationId(12345)
            .setTitle("custom_notification_title")
            .setContent("custom_notification_content");    
    // 展示通知
    MTPushPrivatesApi.showNotification(context,notificationMessage);

        
此代碼塊在浮窗中顯示

清除通知

  • 請先 init,否則調用無效
/** * 清除指定 notifyId 的通知 * * @param context 不為空 * @param notifyId 通知 id */ public static void clearNotification(Context context, int notifyId)
              /**
     * 清除指定 notifyId 的通知
     *
     * @param context  不為空
     * @param notifyId 通知 id
     */
    public static void clearNotification(Context context, int notifyId)

        
此代碼塊在浮窗中顯示

示例代碼如下

// 清除指定 notifyId 的通知 MTPushPrivatesApi.clearNotification(context,12345);
              // 清除指定 notifyId 的通知
    MTPushPrivatesApi.clearNotification(context,12345);

        
此代碼塊在浮窗中顯示

上報廠商通道通知送達

  • 請先 init,否則調用無效
  • 不集成 Engagelab 的廠商包,但需要 Engagelab 統計通知送達率,請調用此接口
/** * 上報廠商通道通知到達 * * 走 http/https 上報 * * @param context 不為空 * @param messageId Engagelab 訊息 id,不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId 廠商訊息 id,可為空 */ public static void reportNotificationArrived(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * 上報廠商通道通知到達
     * 
     * 走 http/https 上報
     *
     * @param context           不為空
     * @param messageId         Engagelab 訊息 id,不為空
     * @param platform          廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId 廠商訊息 id,可為空
     */
    public static void reportNotificationArrived(Context context, String messageId, byte platform, String platformMessageId)

        
此代碼塊在浮窗中顯示

示例代碼如下

// 上報廠商通知到達,messageId 為“12345”,廠商為小米,廠商 messageId 為“MI-6476RHT25” MTPushPrivatesApi.reportNotificationArrived(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");
              // 上報廠商通知到達,messageId 為“12345”,廠商為小米,廠商 messageId 為“MI-6476RHT25”
    MTPushPrivatesApi.reportNotificationArrived(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");

        
此代碼塊在浮窗中顯示

上報廠商通道通知點擊

  • 請先 init,否則調用無效
  • 不集成 Engagelab 的廠商包,但需要 Engagelab 統計通知點擊率,請調用此接口
/** * 上報廠商通道通知點擊 * * 走 http/https 上報 * * @param context 不為空 * @param messageId Engagelab 訊息 id,不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId 廠商訊息 id,可為空 */ public static void reportNotificationClicked(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * 上報廠商通道通知點擊
     * 
     * 走 http/https 上報
     *
     * @param context           不為空
     * @param messageId         Engagelab 訊息 id,不為空
     * @param platform          廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId 廠商訊息 id,可為空
     */
    public static void reportNotificationClicked(Context context, String messageId, byte platform, String platformMessageId)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 上報廠商通知點擊,messageId 為“12345”,廠商為小米,廠商 messageId 為“MI-6476RHT25” MTPushPrivatesApi.reportNotificationClicked(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");
              // 上報廠商通知點擊,messageId 為“12345”,廠商為小米,廠商 messageId 為“MI-6476RHT25”
    MTPushPrivatesApi.reportNotificationClicked(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");

        
此代碼塊在浮窗中顯示

上報廠商通道通知刪除

  • 請先 init,否則調用無效
  • 不集成 Engagelab 的廠商包,但需要 Engagelab 統計通知刪除率,請調用此接口
/** * 上報廠商通道通知刪除 * * 走 http/https 上報 * * @param context 不為空 * @param messageId Engagelab 訊息 id,不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId 廠商訊息 id,可為空 */ public static void reportNotificationDeleted(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * 上報廠商通道通知刪除
     * 
     * 走 http/https 上報
     *
     * @param context           不為空
     * @param messageId         Engagelab 訊息 id,不為空
     * @param platform          廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId 廠商訊息 id,可為空
     */
    public static void reportNotificationDeleted(Context context, String messageId, byte platform, String platformMessageId)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 上報廠商通知刪除,messageId 為“12345”,廠商為 mi,廠商 messageId 為“MI-6476RHT25” MTPushPrivatesApi.reportNotificationDeleted(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");
              // 上報廠商通知刪除,messageId 為“12345”,廠商為 mi,廠商 messageId 為“MI-6476RHT25”
    MTPushPrivatesApi.reportNotificationDeleted(context,“12345”,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476RHT25");

        
此代碼塊在浮窗中顯示

上報廠商通道通知打開

  • 請先 init,否則調用無效
  • 不集成 Engagelab 的廠商包,但需要 Engagelab 統計通知打開率,請調用此接口
  • 有些廠商(例如:huawei/oppo/vivo)沒有通知到達和通知點擊回調,配置通知點擊跳轉的 activity 後,可在跳轉的 activity 內獲取參數上報,建議所有廠商通知點擊跳轉的 activity 都配置
  • MTPush4.0.0 以上版本不需要
/** * 上報廠商通道通知打開 * * 走 http/https 上報 * * @param context 不為空 * @param messageId Engagelab 訊息 id,不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param platformMessageId 廠商訊息 id,可為空 */ public static void reportNotificationOpened(Context context, String messageId, byte platform, String platformMessageId)
              /**
     * 上報廠商通道通知打開
     * 
     * 走 http/https 上報
     *
     * @param context           不為空
     * @param messageId         Engagelab 訊息 id,不為空
     * @param platform          廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param platformMessageId 廠商訊息 id,可為空
     */
    public static void reportNotificationOpened(Context context, String messageId, byte platform, String platformMessageId)

        
此代碼塊在浮窗中顯示

示例代碼如下:

Bundle bundle = intent.getExtras(); String platformMessage = ""; // huawei if (intent.getData() != null){platformMessage = intent.getData().toString();} // 其他廠商 if (TextUtils.isEmpty(platformMessage) && intent.getExtras()!= null) {if (MTGlobal.IS_FOR_JIGUANG) {platformMessage = bundle.getString("JMessageExtra"); }else {platformMessage = bundle.getString("MTMessageExtra"); } } if (TextUtils.isEmpty(platformMessage)) {return;} JSONObject messageJson = new JSONObject(platformMessage); tvMessage.setText(toLogString(messageJson)); // 解析 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"); // 上報通知點擊 activity 打開,建議所有廠商跳轉都加上,僅 MTPush4.0.0 以下版本需要 MTPushPrivatesApi.reportNotificationOpened(this, messageId, platform, "");
              Bundle bundle = intent.getExtras();
    String platformMessage = "";
    // huawei
    if (intent.getData() != null){platformMessage = intent.getData().toString();}
    // 其他廠商
    if (TextUtils.isEmpty(platformMessage) && intent.getExtras()!= null) {if (MTGlobal.IS_FOR_JIGUANG) {platformMessage = bundle.getString("JMessageExtra");
        }else {platformMessage = bundle.getString("MTMessageExtra");
        }
    }
    if (TextUtils.isEmpty(platformMessage)) {return;}
    JSONObject messageJson = new JSONObject(platformMessage);
    tvMessage.setText(toLogString(messageJson));
    // 解析
    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");
    // 上報通知點擊 activity 打開,建議所有廠商跳轉都加上,僅 MTPush4.0.0 以下版本需要
    MTPushPrivatesApi.reportNotificationOpened(this, messageId, platform, "");

        
此代碼塊在浮窗中顯示

上傳廠商 token

  • 請先 init,否則調用無效
  • 由於走 tcp 上傳,需要長連接成功即 onConnectStatus 回調結果為 ture 後調用此接口
  • 不集成 Engagelab 的廠商包,但需要 Engagelab 推播廠商訊息
/** * 上傳廠商 token * * 走 tcp 上傳 * * @param context 不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google) * @param token 廠商返回的 token,不為空 * @param region 海外版小米和oppo需要设置region,国际版填:"GLOBAL",非海外版的填:"NULL" */ public static void uploadPlatformToken(Context context, byte platform, String token, String region)
              /**
     * 上傳廠商 token
     * 
     * 走 tcp 上傳
     *
     * @param context  不為空
     * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、8:google)
     * @param token    廠商返回的 token,不為空
     * @param region    海外版小米和oppo需要设置region,国际版填:"GLOBAL",非海外版的填:"NULL"
     */
    public static void uploadPlatformToken(Context context, byte platform, String token, String region)

        
此代碼塊在浮窗中顯示

示例代碼如下:

// 上报厂商token,厂商为mi,厂商token为“MI-6476s-afs-afs-afaR-HT25” MTPushPrivatesApi.uploadPlatformToken(context,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476s-afs-afs-afaR-HT25","NULL");
              // 上报厂商token,厂商为mi,厂商token为“MI-6476s-afs-afs-afaR-HT25”
    MTPushPrivatesApi.uploadPlatformToken(context,MTPushPrivatesApi.PLATFORM_XIAOMI,"MI-6476s-afs-afs-afaR-HT25","NULL");

        
此代碼塊在浮窗中顯示

錯誤碼

code int值 說明
SUCCESS 0 成功
NULL_TAG_AND_ALIAS 6001 無效的設置
TIMEOUT 6002 設置超時,建議重試,一般出現在網絡不佳、初始化尚未完成時
INVALID_ALIAS 6003 alias字符串不合法,有效的別名、標籤組成:字母(區分大小寫)、數字、下劃線、漢字、特殊字符( 2.1.6 支持)@!#$&*+=.|
TOO_LONG_ALIAS 6004 alias超長。最多 40 個字節,中文 UTF-8 是 3 個字節
INVALID_TAGS 6005 某一個tag字符串不合法,有效的別名、標籤組成:字母(區分大小寫)、數字、下劃線、漢字、特殊字符( 2.1.6 支持)@!#$&*+=.|
TOO_LONG_TAG 6006 某一個tag超長。一個tag最多40個字節,中文UTF-8是3個字節
TOO_MANY_TAGS 6007 tags數量超出限制。最多1000個,這是一台設備的限制。一個應用全局的標籤數量無限制。
TOO_LONG_TAGS 6008 tags操作單次長度超過5000
UNKNOWN_ERROR 6009 未知錯誤
INVALID_JSON 6010 非法json
INVOKE_TOO_SOON 6012 tag/alias操作頻繁
CONNECT_NOT_ENABLE 6013 CONNECT_NOT_ENABLE
INVALID_MOBILE_NUMBER 6023 無效手機號碼

MTCommonReceiver 類

  • 主要用於方法回調
  • 此類中所有方法回調均在主進程

應用程式通知開關狀態回調

  • 每次啟動 sdk 後都會回調當前通知開關狀態
  • 後續通知開關有變化時才會回調
/** * 應用程式通知開關狀態回調 * * @param context 不為空 * @param enable 通知開關是否開,true 為打開,false 為關閉 */ @Override public void onNotificationStatus(Context context, boolean enable)
              /**
     * 應用程式通知開關狀態回調
     *
     * @param context 不為空
     * @param enable  通知開關是否開,true 為打開,false 為關閉
     */
    @Override
    public void onNotificationStatus(Context context, boolean enable)

        
此代碼塊在浮窗中顯示

獲取長連接狀態回調

/** * 長連接是否連接成功 * * 在初始化後會進行長連接,連接成功 / 失敗均會回調此方法 * * @param context 不為空 * @param enable 長連接是否連接成功,true 為成功;false 為失敗 */ public void onConnectStatus(Context context, boolean enable)
              /**
     * 長連接是否連接成功
     *
     * 在初始化後會進行長連接,連接成功 / 失敗均會回調此方法
     *
     * @param context 不為空
     * @param enable  長連接是否連接成功,true 為成功;false 為失敗   
     */		
        public void onConnectStatus(Context context, boolean enable)

        
此代碼塊在浮窗中顯示

通知訊息送達回調

  • Engagelab/ 小米 / 魅族通道會有此方法回調(google 通道需要應用程式在前台才會有回調)
  • notificationMessage 詳情查看 NotificationMessage
/** * 通知訊息送達 * * 推播的通知訊息送達會回調此方法 * * @param context 不為空 * @param notificationMessage 通知訊息 */ public void onNotificationArrived(Context context, NotificationMessage notificationMessage)
              /**
     * 通知訊息送達
     *
     * 推播的通知訊息送達會回調此方法
     *
     * @param context 						不為空
     * @param notificationMessage 通知訊息  
     */				
        public void onNotificationArrived(Context context, NotificationMessage notificationMessage)

        
此代碼塊在浮窗中顯示

onNotificationUnShow

  • 後台下發前台不顯示通知,且手機app在前台時回調該方法
/** * 通知消息在前台不顯示 * * @param context 不為空 * @param notificationMessage 通知消息 */ @Override public void onNotificationUnShow(Context context, NotificationMessage notificationMessage)
              /**
     * 通知消息在前台不顯示
     *
     * @param context             不為空
     * @param notificationMessage 通知消息
     */
    @Override
    public void onNotificationUnShow(Context context, NotificationMessage notificationMessage)

        
此代碼塊在浮窗中顯示

通知訊息點擊回調

  • Engagelab/ 小米 / 魅族通道會有此方法回調(google 通道需要應用程式在前台才會有回調)
  • notificationMessage 詳情查看 NotificationMessage
/** * 通知訊息點擊 * * 推播的通知訊息點擊會回調此方法 * * @param context 不為空 * @param notificationMessage 通知訊息 */ public void onNotificationClicked(Context context, NotificationMessage notificationMessage)
              /**
     * 通知訊息點擊
     *
         * 推播的通知訊息點擊會回調此方法
         *
     * @param context 						不為空
     * @param notificationMessage 通知訊息  
     */				
        public void onNotificationClicked(Context context, NotificationMessage notificationMessage)

        
此代碼塊在浮窗中顯示

通知訊息刪除回調

  • 只有 Engagelab 通道的通知訊息刪除才會觸發
  • notificationMessage 詳情查看 NotificationMessage
  • 應用程式在死亡狀態時無法回調
/** * 通知訊息刪除 * * 推播的通知訊息刪除會回調此方法 * * @param context 不為空 * @param notificationMessage 通知訊息 */ public void onNotificationDeleted(Context context, NotificationMessage notificationMessage)
              /**
     * 通知訊息刪除
     * 
         * 推播的通知訊息刪除會回調此方法
         *
     * @param context 						不為空
     * @param notificationMessage 通知訊息  
     */				
        public void onNotificationDeleted(Context context, NotificationMessage notificationMessage)

        
此代碼塊在浮窗中顯示

自訂訊息送達回調

  • 自訂訊息不會展示在通知欄
  • 只有 Engagelab 通道的通知訊息刪除才會觸發
  • customMessage 詳情查看 CustomMessage
/** * 自訂訊息送達 * * 自訂訊息送達時會回調此方法 * * @param context 不為空 * @param customMessage 自訂訊息 */ public void onCustomMessage(Context context, CustomMessage customMessage)
              /**
     * 自訂訊息送達
     *
     * 自訂訊息送達時會回調此方法
     *
     * @param context 			不為空
     * @param customMessage 自訂訊息  
     */				
        public void onCustomMessage(Context context, CustomMessage customMessage)

        
此代碼塊在浮窗中顯示

onPlatformToken

  • 廠商token訊息回調
/** *Manufacturer operation information * * @param context ApplicationContext object * @param platformMessage manufacturer token message */ public void onPlatformToken(context context, PlatformTokenMessage platformMessage)
              /**
     *Manufacturer operation information
     *
     * @param context ApplicationContext object
     * @param platformMessage manufacturer token message
     */
    public void onPlatformToken(context context, PlatformTokenMessage platformMessage)

        
此代碼塊在浮窗中顯示

通知頻道配置

Android8.0 以後通知都走 NotificationChannel 了。開發者可以自行定義 NotificationChannel,然後在 API 推送的時候可以指定 channelId 推送; 在 Android8.0 及以上的機型,通知會先查找對應 channelId 的 channel,通知的重要等級、聲音、震動、呼吸燈由 channel 決定; 如果沒有找到 channelId,或者處於靜默時間內,則走預設的engagelab channel。

自定義 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", "自定義通知組"); nm.createNotificationChannelGroup(notificationChannelGroup); NotificationChannel notificationChannel = new NotificationChannel("MyChannelId", "自定義通知", NotificationManager.IMPORTANCE_HIGH); notificationChannel.setGroup("MyGroupId"); notificationChannel.enableLights(true); notificationChannel.enableVibration(true); notificationChannel.setSound("android.resource:// 包名 /raw/ 鈴聲文件", null); // 設置自定義鈴聲 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", "自定義通知組");
                nm.createNotificationChannelGroup(notificationChannelGroup);

                NotificationChannel notificationChannel = new NotificationChannel("MyChannelId", "自定義通知", NotificationManager.IMPORTANCE_HIGH);
                notificationChannel.setGroup("MyGroupId");
                notificationChannel.enableLights(true);
                notificationChannel.enableVibration(true);
                notificationChannel.setSound("android.resource:// 包名 /raw/ 鈴聲文件", null);    // 設置自定義鈴聲

                nm.createNotificationChannel(notificationChannel);
            }
        }
    }

        
此代碼塊在浮窗中顯示

NotificationMessage

通知訊息

屬性 類型 說明
messageId String
  • 必須,EngagelabmessageId,用於訊息跟踪和統計。
  • 不能為空,為空不展示通知
  • platformMessageId String 廠商 messageId,用於廠商訊息跟踪和統計
    notificationId int 通知 id,可調用 clearNotification 取消通知
    smallIcon String 小圖標,默認使用 drawable/mtpush_notification_icon.png
    largeIcon String 大圖標,一般位於通知右邊
    title String 通知標題,為空時取應用程式名
    content String 必須,通知內容,不能為空,為空不展示通知
    extras Bundle 額外字段,key/value 格式均為 String
    builderId int 通知樣式 id,可調用 setNotificationLayout 設置通知樣式,默認使用系統樣式
    style int 通知風格,默認值為 0
  • 大文本風格 NOTIFICATION_STYLE_BIG_TEXT:1
  • 收件箱風格 NOTIFICATION_STYLE_INBOX:2
  • 大圖片風格 NOTIFICATION_STYLE_BIG_PICTURE:3
  • bigText String 大文本,style 為 NOTIFICATION_STYLE_BIG_TEXT 生效
    inbox String[] 收件箱,style 為 NOTIFICATION_STYLE_INBOX 生效
    bigPicture String 大圖片,style 為 NOTIFICATION_STYLE_BIG_PICTURE 生效
    priority int 通知的緊急程度,默認值為 0
  • 低級,通知沒有 led 燈、震動和鈴聲,Notification.PRIORITY_LOW:-1
  • 普通,通知可以 led 燈、震動和鈴聲,Notification.PRIORITY_DEFAULT:0
  • 高級,通知可以 led 燈、震動和鈴聲,還可以懸浮窗彈出,Notification.PRIORITY_HIGH:1
  • defaults int 通知用於鈴聲、震動、led 燈,三種場景可自由組合,例如為 7 時,代表鈴聲、震動、led 燈都有, 默認值為 Notification.DEFAULT_ALL:-1,Android 8.0 開始此屬性跟隨 channel。
  • 鈴聲,Notification.DEFAULT_SOUND:1
  • 震動,Notification.DEFAULT_VIBRATE:2
  • led 燈,Notification.DEFAULT_LIGHTS:4
  • category String 通知類型,用於通知欄的排序或者過濾,種類繁多,類似 Notification.CATEGORY_ALARM、Notification#CATEGORY_CALL
    sound String
  • 通知附帶的鈴聲,需要提前在 res/raw 目錄存在鈴聲文件。
  • Android 8.0 開始,鈴聲跟隨 channel,如果通知使用的 channel 沒有設置鈴聲,此通知不會對自訂鈴聲生效。
  • 建議提前將鈴聲設置在 channel 中,後續傳送通知時的 sound 和 channelId 中的鈴聲保持一致,即可通知鈴聲效果保持一致性。
  • channelId String 從 Android 8.0 開始需要,如果沒有提前設置 sdk 會幫忙設置(僅限 Engagelab 通道和應用程式在前台時的 google 通道)
    intentUri String 點擊通知之後的跳轉,目前僅支持 activity,activity 跳轉使用 Intent.toURI() 轉換得到
    badge int 此通知添加的角標數,屬於累加邏輯,數值需要大於 0,否則無效,建議填 1
  • 僅華為和小米生效
  • 小米點擊通知後,角標數會自動減 1
  • 華為點擊通知後,角標數不會自動減 1,建議調用 setNotificationBadge 設置
  • CustomMessage

    自訂訊息

    屬性 類型 說明
    messageId String 必須,EngagelabmessageId,用於訊息跟踪和統計,不能為空
    platform byte 廠商類型,默認 Engagelab,MTPushPrivatesApi.PLATFORM_DEFAULT:0
  • 小米,MTPushPrivatesApi.PLATFORM_XIAOMI:1
  • 華為,MTPushPrivatesApi.PLATFORM_HUAWEI:2
  • 魅族,MTPushPrivatesApi.PLATFORM_MEIZU:3
  • oppo,MTPushPrivatesApi.PLATFORM_OPPO:4
  • vivo,MTPushPrivatesApi.PLATFORM_VIVO:5
  • google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
  • platformMessageId String 廠商 messageId,用於廠商訊息跟踪和統計
    title String 訊息標題
    content String 訊息標題
    contentType String 訊息類型
    extras Bundle 額外字段,key/value 格式均為 String

    PlatformTokenMessage

    廠商 token 訊息

    屬性 類型 說明
    platform byte
  • 廠商類型,默認 Engagelab,MTPushPrivatesApi.PLATFORM_DEFAULT:0
  • 小米,MTPushPrivatesApi.PLATFORM_XIAOMI:1
  • 華為,MTPushPrivatesApi.PLATFORM_HUAWEI:2
  • 魅族,MTPushPrivatesApi.PLATFORM_MEIZU:3
  • oppo,MTPushPrivatesApi.PLATFORM_OPPO:4
  • vivo,MTPushPrivatesApi.PLATFORM_VIVO:5
  • google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
  • token String 廠商返回的 token
    在文档中心打开