logo產品文件
搜尋
登錄

MTPush-API

MTCorePrivatesApi

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

configAppKey

  • 需要在Application.onCreate()方法中調用
  • 請在#init之前調用
/** * 配置應用key,不使用AndroidManifest.xml中的配置 * * 需要在Application.onCreate()方法中調用 * 請在#init之前調用 * * @param context 不為空 * @param appKey 不為空 */ public static void configAppKey(Context context, String appKey)
              
                  /**
     * 配置應用key,不使用AndroidManifest.xml中的配置
     *
     * 需要在Application.onCreate()方法中調用
     * 請在#init之前調用
     *
     * @param context 不為空
     * @param appKey 不為空
     */
    public static void configAppKey(Context context, String appKey)

            
此代碼塊在浮窗中顯示

代碼示例如下

MTCorePrivatesApi.configAppKey(this,"你的appkey");
              
              MTCorePrivatesApi.configAppKey(this,"你的appkey");

            
此代碼塊在浮窗中顯示

configAppChannel

  • 需要在Application.onCreate()方法中調用
  • 請在#init之前調用
/** * 配置應用渠道,不使用AndroidManifest.xml中的配置 * 需要在Application.onCreate()方法中調用 * 需在init前,並要在Application.onCreate內使用 * * @param context 不為空 * @param appChannel 不為空 */ public static void configAppChannel(Context context, String appChannel)
              
                   /**
         * 配置應用渠道,不使用AndroidManifest.xml中的配置
         * 需要在Application.onCreate()方法中調用
         * 需在init前,並要在Application.onCreate內使用
         *
         * @param context    不為空
         * @param appChannel 不為空
         */
    public static void configAppChannel(Context context, String appChannel)

            
此代碼塊在浮窗中顯示

代碼示例如下

MTCorePrivatesApi.configAppChannel(this,"你的appChannel");
              
              MTCorePrivatesApi.configAppChannel(this,"你的appChannel");

            
此代碼塊在浮窗中顯示

configAppSiteName

  • 需要在Application.onCreate()方法中調用
  • 請在#init之前調用
/** * 配置數據中心站點名稱,不使用AndroidManifest.xml中的配置 * 目前可選的節點有Singapore、USA_Virginia、DEU_Frankfurt和HongKong。 * 需要在Application.onCreate()方法中調用 * 請在#init之前調用 * * @param context 不為空 * @param appSiteName 不為空 */ public static void configAppSiteName(Context context, String appSiteName)
              
                  /**
     * 配置數據中心站點名稱,不使用AndroidManifest.xml中的配置
     * 目前可選的節點有Singapore、USA_Virginia、DEU_Frankfurt和HongKong。
     * 需要在Application.onCreate()方法中調用
     * 請在#init之前調用
     *
     * @param context 不為空
     * @param appSiteName 不為空
     */
    public static void configAppSiteName(Context context, String appSiteName)

            
此代碼塊在浮窗中顯示

代碼示例如下

MTCorePrivatesApi.configAppSiteName(this,"你的平台數據中心站點名稱");
              
              MTCorePrivatesApi.configAppSiteName(this,"你的平台數據中心站點名稱");

            
此代碼塊在浮窗中顯示

configHeartbeatInterval

  • 需要在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);

            
此代碼塊在浮窗中顯示

configConnectRetryCount

  • 需要在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);

            
此代碼塊在浮窗中顯示

configDebugMode

  • 需要在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);

            
此代碼塊在浮窗中顯示

configSM4

  • 需要在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());

            
此代碼塊在浮窗中顯示

getUserId

返回值為空時需要注意是否配置了環境,是否調用了初始化

如果檢查配置無誤,可能還在連接過程中,可在#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);

            
此代碼塊在浮窗中顯示

getRegistrationId

返回值為空時需要注意是否配置了環境,是否調用了初始化

如果檢查配置無誤,可能還在連接過程中,可在#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 = MTCorePrivatesApi.getRegistrationId(context);
              
              String registrationId = MTCorePrivatesApi.getRegistrationId(context);

            
此代碼塊在浮窗中顯示

setEnableResetOnDeviceChange

  • 需要在Application.onCreate()方法中調用
  • 請在#init之前調用
  • 默認為 false(不啟用)
/** * 配置設備遷移功能 * 如果啟用,當設備型號發生變化時,會清除本地的註冊id、uid資訊,重新註冊 * 默認為false * * @param context 不為空 * @param enable 是否啟用設備遷移,true為啟用,false為禁用 */ public static void setEnableResetOnDeviceChange(Context context, boolean enable)
              
                  /**
     * 配置設備遷移功能
     * 如果啟用,當設備型號發生變化時,會清除本地的註冊id、uid資訊,重新註冊
     * 默認為false
     *
     * @param context 不為空
     * @param enable  是否啟用設備遷移,true為啟用,false為禁用
     */
    public static void setEnableResetOnDeviceChange(Context context, boolean enable)

            
此代碼塊在浮窗中顯示

代碼示例如下

  • 當設備型號發生變化時(如刷機、換設備等),會自動清除本地緩存的註冊資訊
// 啟用設備遷移功能 MTCorePrivatesApi.setEnableResetOnDeviceChange(this, true); // 禁用設備遷移功能(默認狀態) MTCorePrivatesApi.setEnableResetOnDeviceChange(this, false);
              
                      // 啟用設備遷移功能
        MTCorePrivatesApi.setEnableResetOnDeviceChange(this, true);
        
        // 禁用設備遷移功能(默認狀態)
        MTCorePrivatesApi.setEnableResetOnDeviceChange(this, false);

            
此代碼塊在浮窗中顯示

MTPushPrivatesApi

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

configOldPushVersion

  • 後台沒升級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());   
    }
}

            
此代碼塊在浮窗中顯示

configUserLanguage

/** * 配置push通知語言,在MTPushPrivatesApi.init後使用 * * @param context 不為空 * @param pushLanguage 為空字符串時,恢復使用手機語言 */ public static void configUserLanguage(Context context, String pushLanguage)
              
                  /**
     * 配置push通知語言,在MTPushPrivatesApi.init後使用
     *
     * @param context      不為空
     * @param pushLanguage 為空字符串時,恢復使用手機語言
     */
    public static void configUserLanguage(Context context, String pushLanguage)

            
此代碼塊在浮窗中顯示

代碼示例如下:

MTPushPrivatesApi.configUserLanguage(context,"zh-Hans");
              
                  MTPushPrivatesApi.configUserLanguage(context,"zh-Hans");  

            
此代碼塊在浮窗中顯示

支持的語言碼詳見https://www.engagelab.com/zh_CN/docs/app-push/developer-guide/rest-api/create-push-api#%E5%A4%9A%E8%AF%AD%E8%A8%80%E7%A0%81

setEnablePushTextToSpeech

/** * 語音播報功能設置,需要導入語音包(mt-sdk-sound-x.x.x.aar) * * @param context 不為空 * @param enable true為打開,false為關閉,默認為false */ public static void setEnablePushTextToSpeech(Context context, boolean enable)
              
                  /**
     * 語音播報功能設置,需要導入語音包(mt-sdk-sound-x.x.x.aar)
     *
     * @param context      不為空
     * @param enable true為打開,false為關閉,默認為false
     */
    public static void setEnablePushTextToSpeech(Context context, boolean enable)

            
此代碼塊在浮窗中顯示

代碼示例如下:

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

            
此代碼塊在浮窗中顯示

init

  • 建議在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());   
    }
}

            
此代碼塊在浮窗中顯示

goToAppNotificationSettings

  • 啟動sdk後可根據#onNotificationStatus回調結果,再決定是否需要調用此借口
/** * 前往通知開關設置頁面 * * @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){
                        // 已設置通知開關為打開
                }	    
    }

            
此代碼塊在浮窗中顯示

turnOnPush

  • 一般用於在調用#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 推播成功
    }				
}				

            
此代碼塊在浮窗中顯示

turnOffPush

  • 一般用於關閉 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 推播成功
    }
}		

            
此代碼塊在浮窗中顯示

addTag

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onTagMessage會回調結果
/** * 增加指定tag,累加邏輯,之前設置的標籤依然存在 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 * @param tags 標籤數組,每個tag命名長度限制為40字節,最多支持設置1000個tag,且單次操作總長度不得超過5000字節 */ public static void addTag(Context context, int sequence, String... tags)
              
                  /**
     * 增加指定tag,累加邏輯,之前設置的標籤依然存在
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     * @param tags     標籤數組,每個tag命名長度限制為40字節,最多支持設置1000個tag,且單次操作總長度不得超過5000字節
     */
    public static void addTag(Context context, int sequence, String... tags)

            
此代碼塊在浮窗中顯示

代碼示例如下

// 這裏定義一個常量,代表增加指定tag操作 private static final int SEQUENCE_TAG_ADD = 1; // 增加tag:"china","guangdong","shenzhen" MTPushPrivatesApi.addTag(context,SEQUENCE_TAG_ADD,"china","guangdong","shenzhen") // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調 @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_ADD){ // 增加指定tag成功,此時可查看操作成功的tag數組 String[] tags = tagMessage.getTags(); } }
              
                      // 這裏定義一個常量,代表增加指定tag操作
        private static final int SEQUENCE_TAG_ADD = 1;
        // 增加tag:"china","guangdong","shenzhen"
        MTPushPrivatesApi.addTag(context,SEQUENCE_TAG_ADD,"china","guangdong","shenzhen")
            
        // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調
        @Override
        public void onTagMessage(Context context, TagMessage tagMessage){
                if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
                        // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                        return;
                }
                if(tagMessage.getSequence() == SEQUENCE_TAG_ADD){
                        // 增加指定tag成功,此時可查看操作成功的tag數組
                        String[] tags = tagMessage.getTags();
                }
        }

            
此代碼塊在浮窗中顯示

deleteTag

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onTagMessage會回調結果
/** * 刪除指定tag,刪除邏輯,會刪除指定的標籤 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 * @param tags 標籤數組,每個tag命名長度限制為40字節,最多支持設置1000個tag,且單次操作總長度不得超過5000字節 */ public static void deleteTag(Context context, int sequence, String... tags)
              
                  /**
     * 刪除指定tag,刪除邏輯,會刪除指定的標籤
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     * @param tags     標籤數組,每個tag命名長度限制為40字節,最多支持設置1000個tag,且單次操作總長度不得超過5000字節
     */
    public static void deleteTag(Context context, int sequence, String... tags)

            
此代碼塊在浮窗中顯示

代碼示例如下:

// 這裏定義一個常量,代表刪除指定tag操作 private static final int SEQUENCE_TAG_DELETE = 2; // 刪除tag:"china","guangdong","shenzhen" MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE,"china","guangdong","shenzhen") // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調 @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE){ // 刪除指定tag成功,此時可查看操作成功的tag數組 String[] tags = tagMessage.getTags(); } }
              
                  // 這裏定義一個常量,代表刪除指定tag操作
    private static final int SEQUENCE_TAG_DELETE = 2;
    // 刪除tag:"china","guangdong","shenzhen"
    MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE,"china","guangdong","shenzhen")
    
    // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調
    @Override
    public void onTagMessage(Context context, TagMessage tagMessage){
            if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE){
                    // 刪除指定tag成功,此時可查看操作成功的tag數組
                    String[] tags = tagMessage.getTags();
            }
    }

            
此代碼塊在浮窗中顯示

updateTag

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onTagMessage會回調結果
/** * 更新指定tag,覆蓋邏輯,之前添加的tag會清空 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 * @param tags 標籤數組,每個tag命名長度限制為40字節,最多支持設置1000個tag,且單次操作總長度不得超過5000字節 */ public static void updateTag(Context context, int sequence, String... tags)
              
                  /**
     * 更新指定tag,覆蓋邏輯,之前添加的tag會清空
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     * @param tags     標籤數組,每個tag命名長度限制為40字節,最多支持設置1000個tag,且單次操作總長度不得超過5000字節
     */
    public static void updateTag(Context context, int sequence, String... tags)

            
此代碼塊在浮窗中顯示

代碼示例如下:

// 這裏定義一個常量,代表更新指定tag操作 private static final int SEQUENCE_TAG_UPDATE = 3; // 更新tag:"beijing","shanghai","guangzhou","shenzhen",之前設置的tag會失效 MTPushPrivatesApi.updateTag(context,SEQUENCE_TAG_UPDATE,"beijing","shanghai","guangzhou","shenzhen") // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調 @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_UPDATE){ // 更新指定tag成功,此時可查看操作成功的tag數組 String[] tags = tagMessage.getTags(); } }
              
                  // 這裏定義一個常量,代表更新指定tag操作
    private static final int SEQUENCE_TAG_UPDATE = 3;
    // 更新tag:"beijing","shanghai","guangzhou","shenzhen",之前設置的tag會失效
    MTPushPrivatesApi.updateTag(context,SEQUENCE_TAG_UPDATE,"beijing","shanghai","guangzhou","shenzhen")
    
    // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調
    @Override
    public void onTagMessage(Context context, TagMessage tagMessage){
            if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(tagMessage.getSequence() == SEQUENCE_TAG_UPDATE){
                    // 更新指定tag成功,此時可查看操作成功的tag數組
                    String[] tags = tagMessage.getTags();
            }
    }

            
此代碼塊在浮窗中顯示

queryTag

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onTagMessage會回調結果
/** * 查詢指定tag * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 * @param tag 標籤,每個tag命名長度限制為40字節 */ public static void queryTag(Context context, int sequence, String tag)
              
                  /**
     * 查詢指定tag
     * 
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     * @param tag      標籤,每個tag命名長度限制為40字節
     */
    public static void queryTag(Context context, int sequence, String tag)

            
此代碼塊在浮窗中顯示

代碼示例如下

// 這裏定義一個常量,代表查詢指定tag操作 private static final int SEQUENCE_TAG_QUERY = 4; // 查詢標籤 MTPushPrivatesApi.queryTag(context,SEQUENCE_TAG_QUERY,"china") // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調 @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(tageMessage.getSequence() == SEQUENCE_TAG_QUERY){ // 查詢指定tag成功,此時可查看操作成功的tag和狀態 String tag = tagMessage.getQueryTag(); boolean valid = tagMessage.isQueryTagValid(); } }
              
                  // 這裏定義一個常量,代表查詢指定tag操作
    private static final int SEQUENCE_TAG_QUERY = 4;
    // 查詢標籤
    MTPushPrivatesApi.queryTag(context,SEQUENCE_TAG_QUERY,"china")
    
    // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調
    @Override
    public void onTagMessage(Context context, TagMessage tagMessage){
            if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(tageMessage.getSequence() == SEQUENCE_TAG_QUERY){
                    // 查詢指定tag成功,此時可查看操作成功的tag和狀態
                    String tag = 	tagMessage.getQueryTag();
                    boolean valid = tagMessage.isQueryTagValid();
            }
    }	

            
此代碼塊在浮窗中顯示

deleteAllTag

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onTagMessage會回調結果
/** * 刪除所有tag,清空邏輯,會刪除所有的標籤 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 */ public static void deleteAllTag(Context context, int sequence, String... tags)
              
                  /**
     * 刪除所有tag,清空邏輯,會刪除所有的標籤
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     */
    public static void deleteAllTag(Context context, int sequence, String... tags)

            
此代碼塊在浮窗中顯示

代碼示例如下:

// 這裏定義一個常量,代表刪除所有tag操作 private static final int SEQUENCE_TAG_DELETE_ALL = 5; // 刪除所有tag MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE_ALL) // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調 @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){ // 刪除所有tag成功 } }
              
                  // 這裏定義一個常量,代表刪除所有tag操作
    private static final int SEQUENCE_TAG_DELETE_ALL = 5;
    // 刪除所有tag
    MTPushPrivatesApi.deleteTag(context,SEQUENCE_TAG_DELETE_ALL)
    
    // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調
    @Override
    public void onTagMessage(Context context, TagMessage tagMessage){
            if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // tag操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){
                    // 刪除所有tag成功
            }
    }

            
此代碼塊在浮窗中顯示

queryAllTag

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onTagMessage會回調結果
/** * 查詢所有tag,獲取邏輯,會獲取所有標籤 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 */ public static void queryAllTag(Context context, int sequence, String... tags)
              
                  /**
     * 查詢所有tag,獲取邏輯,會獲取所有標籤
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     */
    public static void queryAllTag(Context context, int sequence, String... tags)

            
此代碼塊在浮窗中顯示

代碼示例如下:

// 這裏定義一個常量,代表查詢所有tag操作 private static final int SEQUENCE_TAG_QUERY_ALL = 6; // 查詢所有tag MTPushPrivatesApi.queryAllTag(context,SEQUENCE_TAG_QUERY_ALL) // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調 @Override public void onTagMessage(Context context, TagMessage tagMessage){ if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){ // tag 操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){ // 查詢所有tag成功,此時可查看操作成功的tag數組 String[] tags = tagMessage.getTags(); } }
              
                  // 這裏定義一個常量,代表查詢所有tag操作
    private static final int SEQUENCE_TAG_QUERY_ALL = 6;
    // 查詢所有tag
    MTPushPrivatesApi.queryAllTag(context,SEQUENCE_TAG_QUERY_ALL)
    
    // 繼承MTCommonReceiver後,復寫onTagMessage方法,獲取tag操作回調
    @Override
    public void onTagMessage(Context context, TagMessage tagMessage){
            if(tagMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // tag 操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(tagMessage.getSequence() == SEQUENCE_TAG_DELETE_ALL){
                    // 查詢所有tag成功,此時可查看操作成功的tag數組
                    String[] tags = tagMessage.getTags();
            }
    }

            
此代碼塊在浮窗中顯示

setAlias

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onAliasMessage會回調結果
/** * 設置alias * * 同一個應用程序內,對不同的用戶,建議取不同的別名。這樣,盡可能根據別名來唯一確定用戶 * * 不限定一個別名只能指定一個用戶 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 * @param alias 有效的別名組成:字母(區分大小寫)、數字、下劃線、漢字、特殊字符@!#$&*+=.|。限制:alias命名長度限制為 40 字節(判斷長度需采用 UTF-8 編碼) * */ public static void setAlias(Context context, int sequence, String alias)
              
                  /**
     * 設置alias
     * 
     * 同一個應用程序內,對不同的用戶,建議取不同的別名。這樣,盡可能根據別名來唯一確定用戶
     * 
     * 不限定一個別名只能指定一個用戶
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     * @param alias    有效的別名組成:字母(區分大小寫)、數字、下劃線、漢字、特殊字符@!#$&*+=.|。限制:alias命名長度限制為 40 字節(判斷長度需采用 UTF-8 編碼)
     *                             
     */
    public static void setAlias(Context context, int sequence, String alias) 

            
此代碼塊在浮窗中顯示

示例代碼如下

// 這裏定義一個常量,代表設置alias操作 private static final int SEQUENCE_ALIAS_SET = 7; // 設置alias:"young" MTPushPrivatesApi.setAlias(context,SEQUENCE_ALIAS_SET,"young") // 繼承MTCommonReceiver後,復寫onAliasMessage方法,獲取alias操作回調 @Override public void onAliasMessage(Context context, AliasMessage aliasMessage){ if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){ // alias操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(aliasMessage.getSequence() == SEQUENCE_ALIAS_SET){ // 設置alias成功,此時可查看操作成功的alias String alias = aliasMessage.getAlias(); } }
              
                  // 這裏定義一個常量,代表設置alias操作
    private static final int SEQUENCE_ALIAS_SET = 7;
    // 設置alias:"young"
    MTPushPrivatesApi.setAlias(context,SEQUENCE_ALIAS_SET,"young")
    
    // 繼承MTCommonReceiver後,復寫onAliasMessage方法,獲取alias操作回調
    @Override
    public void onAliasMessage(Context context, AliasMessage aliasMessage){
            if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // alias操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(aliasMessage.getSequence() == SEQUENCE_ALIAS_SET){
                    // 設置alias成功,此時可查看操作成功的alias
                    String alias = 	aliasMessage.getAlias();
            }
    }	

            
此代碼塊在浮窗中顯示

getAlias

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onAliasMessage會回調結果
/** * 獲取alias * * 同一個應用程序內,對不同的用戶,建議取不同的別名。這樣,盡可能根據別名來唯一確定用戶 * * 不限定一個別名只能指定一個用戶 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 */ public static void getAlias(Context context, int sequence)
              
                  /**
     * 獲取alias
     * 
     * 同一個應用程序內,對不同的用戶,建議取不同的別名。這樣,盡可能根據別名來唯一確定用戶
     * 
     * 不限定一個別名只能指定一個用戶
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     */
    public static void getAlias(Context context, int sequence)

            
此代碼塊在浮窗中顯示

示例代碼如下:

// 這裏定義一個常量,代表獲取alias操作 private static final int SEQUENCE_ALIAS_GET = 8; // 獲取alias MTPushPrivatesApi.getAlias(context,SEQUENCE_ALIAS_GET) // 繼承MTCommonReceiver後,復寫onAliasMessage方法,獲取alias操作回調 @Override public void onAliasMessage(Context context, AliasMessage aliasMessage){ if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){ // alias 操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(aliasMessage.getSequence() == SEQUENCE_ALIAS_GET){ // 獲取alias成功,此時可查看操作成功的alias String alias = aliasMessage.getAlias(); } }
              
                  // 這裏定義一個常量,代表獲取alias操作
    private static final int SEQUENCE_ALIAS_GET = 8;
    // 獲取alias
    MTPushPrivatesApi.getAlias(context,SEQUENCE_ALIAS_GET)
    
    // 繼承MTCommonReceiver後,復寫onAliasMessage方法,獲取alias操作回調
    @Override
    public void onAliasMessage(Context context, AliasMessage aliasMessage){
            if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // alias 操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(aliasMessage.getSequence() == SEQUENCE_ALIAS_GET){
                    // 獲取alias成功,此時可查看操作成功的alias
                    String alias = 	aliasMessage.getAlias();
            }
    }	

            
此代碼塊在浮窗中顯示

clearAlias

  • 請先#init,否則調用無效
  • 如果環境沒有問題,#onAliasMessage會回調結果
/** * 清除alias * * 同一個應用程序內,對不同的用戶,建議取不同的別名。這樣,盡可能根據別名來唯一確定用戶 * * 不限定一個別名只能指定一個用戶 * * @param context 不能為空 * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性 */ public static void clearAlias(Context context, int sequence)
              
                  /**
     * 清除alias
     *
     * 同一個應用程序內,對不同的用戶,建議取不同的別名。這樣,盡可能根據別名來唯一確定用戶
     * 
     * 不限定一個別名只能指定一個用戶
     *
     * @param context  不能為空
     * @param sequence 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
     */
    public static void clearAlias(Context context, int sequence)

            
此代碼塊在浮窗中顯示

示例代碼如下:

// 這裏定義一個常量,代表清除alias操作 private static final int SEQUENCE_ALIAS_CLEAR = 7; // 清除alias MTPushPrivatesApi.clearAlias(context,SEQUENCE_ALIAS_CLEAR) // 繼承MTCommonReceiver後,復寫onAliasMessage方法,獲取alias操作回調 @Override public void onAliasMessage(Context context, AliasMessage aliasMessage){ if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){ // alias操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code return; } if(aliasMessage.getSequence() == SEQUENCE_ALIAS_CLEAR){ // 清除alias成功 } }
              
                  // 這裏定義一個常量,代表清除alias操作
    private static final int SEQUENCE_ALIAS_CLEAR = 7;
    // 清除alias
    MTPushPrivatesApi.clearAlias(context,SEQUENCE_ALIAS_CLEAR)
    
    // 繼承MTCommonReceiver後,復寫onAliasMessage方法,獲取alias操作回調
    @Override
    public void onAliasMessage(Context context, AliasMessage aliasMessage){
            if(aliasMessage.getCode != MTPushPrivatesApi.Code.Success){
                    // alias操作失敗,詳細錯誤信息可查看MTPushPrivatesApi.Code
                    return;
            }
            if(aliasMessage.getSequence() == SEQUENCE_ALIAS_CLEAR){
                    // 清除alias成功
            }
    }	

            
此代碼塊在浮窗中顯示

setNotificationShowTime

  • 請先#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);

            
此代碼塊在浮窗中顯示

resetNotificationShowTime

  • 請先#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);

            
此代碼塊在浮窗中顯示

setNotificationSilenceTime

  • 請先#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);

            
此代碼塊在浮窗中顯示

resetNotificationSilenceTime

  • 請先#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);

            
此代碼塊在浮窗中顯示

setNotificationLayout

  • 請先#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);

            
此代碼塊在浮窗中顯示

resetNotificationLayout

  • 請先#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);

            
此代碼塊在浮窗中顯示

setNotificationCount

  • 請先#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);

            
此代碼塊在浮窗中顯示

resetNotificationCount

  • 請先#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);

            
此代碼塊在浮窗中顯示

setNotificationBadge

  • 請先#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);

            
此代碼塊在浮窗中顯示

resetNotificationBadge

  • 請先#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);

            
此代碼塊在浮窗中顯示

showNotification

  • 請先#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);

            
此代碼塊在浮窗中顯示

clearNotification

  • 請先#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);

            
此代碼塊在浮窗中顯示

reportNotificationArrived

  • 請先#init,否則調用無效
  • 不集成Engagelab的廠商包,但需要Engagelab統計通知送達率,請調用此接口
/** * 上報廠商通道通知到達 * * 走http/https上報 * * @param context 不為空 * @param messageId Engagelab訊息id,不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、7:honor、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:mi2:huawei3:meizu4:oppo5:vivo7:honor8: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");

            
此代碼塊在浮窗中顯示

reportNotificationClicked

  • 請先#init,否則調用無效
  • 不集成Engagelab的廠商包,但需要Engagelab統計通知點擊率,請調用此接口
/** * 上報廠商通道通知點擊 * * 走http/https上報 * * @param context 不為空 * @param messageId Engagelab訊息id,不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、7:honor、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:mi2:huawei3:meizu4:oppo5:vivo7:honor8: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");

            
此代碼塊在浮窗中顯示

reportNotificationDeleted

  • 請先#init,否則調用無效
  • 不集成Engagelab的廠商包,但需要Engagelab統計通知刪除率,請調用此接口
/** * 上報廠商通道通知刪除 * * 走http/https上報 * * @param context 不為空 * @param messageId Engagelab訊息id,不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、7:honor、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:mi2:huawei3:meizu4:oppo5:vivo7:honor8: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");

            
此代碼塊在浮窗中顯示

reportNotificationOpened

  • 請先#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、7:honor、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:mi2:huawei3:meizu4:oppo5:vivo7:honor8: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 (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)); // 解析 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 (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));
    // 解析
    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, ""); 

            
此代碼塊在浮窗中顯示

uploadPlatformToken

  • 請先#init,否則調用無效
  • 由於走tcp上傳,需要長連接成功即#onConnectStatus回調結果為ture後調用此接口
  • 不集成Engagelab的廠商包,但需要Engagelab推播廠商訊息
/** * 上傳廠商token * * 走tcp上傳 * * @param context 不為空 * @param platform 廠商,取值範圍(1:mi、2:huawei、3:meizu、4:oppo、5:vivo、7:honor、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:mi2:huawei3:meizu4:oppo5:vivo7:honor8: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");

            
此代碼塊在浮窗中顯示

clearPlatformToken

  • 請先#init,否則調用無效
  • 由於走tcp上傳,需要長連接成功即#onConnectStatus回調結果為ture後調用此接口
  • 不集成Engagelab的廠商包,但需要Engagelab推播廠商訊息
/** * 清除token,調用此接口後,只能通過uploadPlatformToken上報token,sdk不會再主動獲取token上報,冷啟動後重置 * 通過回調onPlatformToken監聽,回調platform為-128時,表示清除成功。 * * 需tcp連接 * * @param context 不為空 */ public static void clearPlatformToken(Context context)
              
                  /**
     * 清除token,調用此接口後,只能通過uploadPlatformToken上報token,sdk不會再主動獲取token上報,冷啟動後重置
     * 通過回調onPlatformToken監聽,回調platform為-128時,表示清除成功。
     * 
     * 需tcp連接
     *
     * @param context  不為空
     */
    public static void clearPlatformToken(Context context)

            
此代碼塊在浮窗中顯示

示例代碼如下

MTPushPrivatesApi.clearPlatformToken(context);
              
                  MTPushPrivatesApi.clearPlatformToken(context);

            
此代碼塊在浮窗中顯示

onFragmentResume

  • 請先#init,否則調用無效
/** * @param context 不為空 * @param fragmentName Fragment頁面完整類名(this.getClass().getCanonicalName()) */ public static void onFragmentResume(Context context, String fragmentName)
              
                  /**
     * @param context           不為空
     * @param fragmentName      Fragment頁面完整類名(this.getClass().getCanonicalName())
     */
    public static void onFragmentResume(Context context, String fragmentName)

            
此代碼塊在浮窗中顯示

onFragmentPause

  • 請先#init,否則調用無效
/** * @param context 不為空 * @param fragmentName Fragment頁面完整類名(this.getClass().getCanonicalName() */ public static void onFragmentPause(Context context, String fragmentName)
              
                  /**
     * @param context           不為空
     * @param fragmentName      Fragment頁面完整類名(this.getClass().getCanonicalName()
     */
    public static void onFragmentPause(Context context, String fragmentName)

            
此代碼塊在浮窗中顯示

使用說明: 因為 Android 添加 Fragment 方式共有四種,而每種不同的添加方式,需要對Fragment的處理方式也有不一樣。下面就針對 Fragment 的四種方式,指定在指定 Fragment 展示 in app 控制方式,分別進行說明。

fragment使用方式 是否可以監聽到Fragment生命周期 極光動態指定展示頁面接口調用方式
方式一:add/show/hide 無法監聽生命周期 Fragment 內的 onFragmentResume 與 onHiddenChaned 回調調用
方式二:ViewPager 無法監聽生命周期 Fragment 內的 setUserVisibleHint 回調調用
方式三:replace 可以監聽生命周期 Fragment 內的生命周期回調 onResume與onPause 調用
方式四:attach/detach 可以監聽生命周期 Fragment 內的生命周期回調 onResume 與 onPause 調用
  • add/show/hide方式

    1)在 Fragment的onCreateView 回調函數中調用動態控制接口,並要求傳入參數。 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { String classname = this.getClass().getCanonicalName(); MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname); return inflater.inflate(R.layout.black_fragment, container, false); } 2)在 Fragment 的 onHiddenChaned 回調接口中,調用動態控制接口,並按要求傳入參數。 @Override public void onHiddenChanged(boolean hidden) { String classname = this.getClass().getCanonicalName(); if(!hidden){//context傳application context MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname); }else{//hide MTPushPrivatesApi.onFragmentPaused(MyApplication.gContext, classname); } super.onHiddenChanged(hidden); }
                  
                  1)在 Fragment的onCreateView 回調函數中調用動態控制接口,並要求傳入參數。
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        String classname = this.getClass().getCanonicalName();
        MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname);
        return inflater.inflate(R.layout.black_fragment, container, false);
    }  
    
    2)在 Fragment 的 onHiddenChaned 回調接口中,調用動態控制接口,並按要求傳入參數。
    
    @Override
    public void onHiddenChanged(boolean hidden) {
        String classname = this.getClass().getCanonicalName();
        if(!hidden){//context傳application context
            MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname);
        }else{//hide
            MTPushPrivatesApi.onFragmentPaused(MyApplication.gContext, classname);  
        } 
        
        super.onHiddenChanged(hidden);
    }  
    
                
    此代碼塊在浮窗中顯示
  • ViewPager方式

    1)在 Fragment 的 setUserVisibleHint 回調接口中,調用動態控制接口,並按要求傳入參數。 @Override public void setUserVisibleHint(boolean isVisibleToUser) { String classname = this.getClass().getCanonicalName(); if(isVisibleToUser){ //傳application context MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname); }else{//hide MTPushPrivatesApi.onFragmentPause(MyApplication.gContext, classname); } super.setUserVisibleHint(isVisibleToUser); }
                  
                  1)在 Fragment 的 setUserVisibleHint 回調接口中,調用動態控制接口,並按要求傳入參數。
    
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        String classname = this.getClass().getCanonicalName();
        if(isVisibleToUser){
            //傳application context
            MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname);
        }else{//hide
            MTPushPrivatesApi.onFragmentPause(MyApplication.gContext, classname);  
        } 
        
        super.setUserVisibleHint(isVisibleToUser);
    }    
    
                
    此代碼塊在浮窗中顯示
  • replace 方式或 attach/detach 方式

    在添加Fragment內的生命周期回調接口中,調用動態頁面配置接口。 @Override public void onResume() {//傳application context String classname = this.getClass().getCanonicalName(); MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname); super.onResume(); } @Override public void onPause() { String classname = this.getClass().getCanonicalName(); MTPushPrivatesApi.onFragmentPause(MyApplication.gContext, classname); super.onPause(); }
                  
                  在添加Fragment內的生命周期回調接口中,調用動態頁面配置接口。
    
    @Override
    public void onResume() {//傳application context
        String classname = this.getClass().getCanonicalName();
        MTPushPrivatesApi.onFragmentResumed(MyApplication.gContext, classname);
        super.onResume();
    }
    
    @Override
    public void onPause() {
        String classname = this.getClass().getCanonicalName();
        MTPushPrivatesApi.onFragmentPause(MyApplication.gContext, classname);  
        super.onPause();
    }
    
                
    此代碼塊在浮窗中顯示

MTCommonReceiver

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

onNotificationStatus

  • 每次啟動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)

            
此代碼塊在浮窗中顯示

onConnectStatus

/** * 長連接是否連接成功 * * 在初始化後會進行長連接,連接成功/失敗均會回調此方法 * * @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)

            
此代碼塊在浮窗中顯示

onNotificationArrived

  • 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)

            
此代碼塊在浮窗中顯示

onNotificationClicked

  • 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)

            
此代碼塊在浮窗中顯示

onNotificationDeleted

  • 只有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)

            
此代碼塊在浮窗中顯示

onCustomMessage

  • 自定義訊息不會展示在通知欄
  • 只有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)

            
此代碼塊在浮窗中顯示

onTagMessage

  • tagMessage詳情查看#TagMessage
/** * tag操作訊息 * * @param context 不為空 * @param tagMessage 標籤信息 */ public void onTagMessage(Context context, TagMessage tagMessage)
              
                  /**
     * tag操作訊息
     *
     * @param context    不為空
     * @param tagMessage 標籤信息
     */		
    public void onTagMessage(Context context, TagMessage tagMessage)

            
此代碼塊在浮窗中顯示

onAliasMessage

  • aliasMessage詳情查看#AliasMessage
/** * alias操作訊息 * * @param context ApplicationContext對象 * @param aliasMessage 別名訊息 */ public void onAliasMessage(Context context, AliasMessage aliasMessage)
              
                  /**
     * alias操作訊息
     *
     * @param context      ApplicationContext對象
     * @param aliasMessage 別名訊息
     */
    public void onAliasMessage(Context context, AliasMessage aliasMessage)

            
此代碼塊在浮窗中顯示

onPlatformToken

  • 廠商token訊息回調
/** * 廠商操作訊息 * * @param context ApplicationContext對象 * @param platformMessage 廠商token訊息 */ public void onPlatformToken(Context context, PlatformTokenMessage platformMessage)
              
                  /**
     * 廠商操作訊息
     *
     * @param context         ApplicationContext對象
     * @param platformMessage 廠商token訊息
     */
    public void onPlatformToken(Context context, PlatformTokenMessage platformMessage)

            
此代碼塊在浮窗中顯示

onInAppMessageShow

  • 應用內訊息展示回調
/** * * * @param context ApplicationContext對象 * @param inAppMessage 應用內訊息 */ public void onInAppMessageShow(Context context, InAppMessage inAppMessage)
              
                  /**
     * 
     *
     * @param context         ApplicationContext對象
     * @param inAppMessage 應用內訊息
     */
    public void onInAppMessageShow(Context context, InAppMessage inAppMessage)

            
此代碼塊在浮窗中顯示

onInAppMessageClick

  • 應用內訊息點擊回調
/** * * * @param context ApplicationContext對象 * @param inAppMessage 應用內訊息 */ public void onInAppMessageClick(Context context, InAppMessage inAppMessage)
              
                  /**
     * 
     *
     * @param context         ApplicationContext對象
     * @param inAppMessage 應用內訊息
     */
    public void onInAppMessageClick(Context context, InAppMessage inAppMessage)

            
此代碼塊在浮窗中顯示

NotificationChannel 配置

支持的版本

開始支持的版本:MTPush SDK v3.3.0

功能說明

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,用於訊息跟蹤和統計,不能為空,為空不展示通知
overrideMessageId String EngagelaboverrideMessageId,用於訊息跟蹤和統計
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
honor,MTPushPrivatesApi.PLATFORM_HONOR:7
google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
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燈,默認值為Notification.DEFAULT_ALL:-1
鈴聲,Notification.DEFAULT_SOUND:1
震動,Notification.DEFAULT_VIBRATE:2
led燈,Notification.DEFAULT_LIGHTS:4
三種場景可自由組合,例如為7時,代表鈴聲、震動、led燈都有
Android8.0開始此屬性跟隨channel
category String 通知類型,用於通知欄的排序或者過濾,
種類繁多,類似Notification.CATEGORY_ALARM、Notification#CATEGORY_CALL
sound String 通知附帶的鈴聲,需要提前在res/raw目錄存在鈴聲文件
Android8.0開始,鈴聲跟隨channel,如果通知使用的channel沒有設置鈴聲,此通知不會對自定義鈴聲生效
建議提前將鈴聲設置在channel中,後續下發通知時的sound和channelId中的鈴聲保持一致,即可通知鈴聲效果保持一致性
channelId String 從Android8.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
honor,MTPushPrivatesApi.PLATFORM_HONOR:7
google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
platformMessageId String 廠商messageId,用於廠商訊息跟蹤和統計
title String 訊息標題
content String 訊息標題
contentType String 訊息類型
extras Bundle 額外字段,key/value格式均為String

TagMessage

  • 標籤訊息
屬性 類型 說明
sequence int 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
code int 操作結果,詳細請查看#code
tags String#addTag
#deleteTag
#updateTag
#queryAllTag
queryTag String 標籤,以下操作會返回
#queryTag
queryTagValid boolean 標籤狀態,以下操作會返回
#queryTag

AliasMessage

  • 別名訊息
屬性 類型 說明
sequence int 用戶自定義的操作序列號,同操作結果一起返回,用來標識一次操作的唯一性
code int 操作結果,詳細請查看#code
alias String 別名,以下操作會返回
#setAlias
#getAlias

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
honor,MTPushPrivatesApi.PLATFORM_HONOR:7
google,MTPushPrivatesApi.PLATFORM_GOOGLE:8
token String 廠商返回的token

InAppMessage

  • 應用內訊息
屬性 類型 說明
messageId String 必須,EngagelabmessageId,用於訊息跟蹤和統計,不能為空,為空不展示
overrideMessageId String EngagelaboverrideMessageId,用於訊息跟蹤和統計
target String 應用內訊息展示目標頁路徑
imageUrl String 應用內訊息圖片地址
extras String 透傳的額外信息
content String 應用內訊息具體內筒
expired long 過期時間
delay long 延遲展示時間
interval long 應用內訊息間隔展示時間
duration long 應用內訊息展示時長
msgTime long SDK接收到應用內訊息時間

code

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 單次操作設備綁定tag數量超出限制,單次最多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 無效手機號
icon
聯繫銷售