Logo Site EngageLab Mark Colored Transparent文件
搜尋

如何實現訊息不折疊展示

在行動應用程式推播場景中,訊息折疊問題會直接影響使用者體驗與資訊觸達效率。本文基於 AppPush 推播產品,從通知訊息(Notification)與自訂訊息(Custom Message)兩種類型出發,詳細說明如何透過技術配置實現訊息展示不折疊的效果。

alt text

一、訊息類型與展示規則對比

通知訊息(Notification)

  • 系統預設行為:
App 狀態 展示規則
前景執行 可透過 group_id 控制折疊邏輯
背景執行 由手機系統接管,預設從通知欄彈出,展示形式受限(如折疊、數量限制等),難以自訂樣式
  • 適用場景: 需透過系統通知欄觸達使用者的標準推播。

自訂訊息(Custom Message)

  • 核心優勢:
    無論 App 處於前景、背景或被一鍵清除狀態,皆可透過用戶端程式碼完全控制訊息展示形式(如彈窗位置、折疊邏輯等)。

  • 適用場景:
    需要客製化互動的高優先級訊息(如訂單狀態提醒、即時聊天)。

二、實現訊息不折疊的兩種方案

方案 1:透過通知訊息實現

(FCM 通道需 App 在前景,EngageLab 通道不區分前景與背景)

實現原理

利用 group_id 欄位控制訊息分組邏輯:

  • 不折疊:為每則訊息分配唯一的 group_id

操作步驟

支援版本:Android SDK V5.0.1 及以上版本支援

推播 API 參數配置(請求體)範例:

{ "notification": { "android": { "group_id": "UNIQUE_GROUP_123" // 唯一值實現不折疊 } } }
              
              {
  "notification": {
    "android": {
      "group_id": "UNIQUE_GROUP_123"  // 唯一值實現不折疊
    }
  }
}

            
此代碼塊在浮窗中顯示

相容性說明

  • 僅支援 FCMEngageLab 推播通道。
  • 若 App 在背景,訊息展示仍受系統限制。

方案 2:透過自訂訊息實現(全場景支援)

實現原理

透過用戶端主動呼叫 showNotification 介面,完全掌控訊息渲染邏輯,規避系統限制。

操作步驟

1. 傳送自訂訊息
{ "message": { "msg_content": "您的訂單已發貨", "content_type": "text", "extras": { "type": "priority_alert", "style": "popup_bottom" // 自訂展示樣式 } } }
              
              {
  "message": {
    "msg_content": "您的訂單已發貨",
    "content_type": "text",
    "extras": {
      "type": "priority_alert",
      "style": "popup_bottom"  // 自訂展示樣式
    }
  }
}

            
此代碼塊在浮窗中顯示
2. 用戶端處理訊息(Android 範例)
public class UserReceiver extends MTCommonReceiver { @Override public void onCustomMessage(Context context, CustomMessage customMessage) { ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString()); showNotification(context, customMessage); // 呼叫展示邏輯 } }
              
              public class UserReceiver extends MTCommonReceiver {
    @Override
    public void onCustomMessage(Context context, CustomMessage customMessage) {
        ExampleLogger.i(TAG, "onCustomMessage:" + customMessage.toString());
        showNotification(context, customMessage); // 呼叫展示邏輯
    }
}

            
此代碼塊在浮窗中顯示
3. 自訂展示邏輯範例(實現不折疊)
public void showNotification(Context context, CustomMessage customMessage) { NotificationMessage notificationMessage = new NotificationMessage() .setMessageId(customMessage.getMessageId()) .setNotificationId("你自訂一個,但每個通知不要一樣") .setTitle(customMessage.getTitle()) .setContent(customMessage.getContent()) .setgroup_id(customMessage.getMessageId()); // 不折疊關鍵欄位 MTPushPrivatesApi.showNotification(context, notificationMessage); }
              
              public void showNotification(Context context, CustomMessage customMessage) {
    NotificationMessage notificationMessage = new NotificationMessage()
        .setMessageId(customMessage.getMessageId())
        .setNotificationId("你自訂一個,但每個通知不要一樣")
        .setTitle(customMessage.getTitle())
        .setContent(customMessage.getContent())
        .setgroup_id(customMessage.getMessageId()); // 不折疊關鍵欄位

    MTPushPrivatesApi.showNotification(context, notificationMessage);
}

            
此代碼塊在浮窗中顯示

優勢對比

能力 通知訊息 自訂訊息
支援 App 狀態 FCM 僅前景,EngageLab 前景、背景皆可 全場景(前景/背景)
樣式自由度 受限(依賴系統) 完全自訂
通道依賴性 需特定通道(FCM、EngageLab) 無限制

三、注意事項

  1. 通道相容性

    • group_id 功能目前僅支援 FCM 與 EngageLab 通道,其他通道暫不支援。
  2. 效能最佳化

    • 高頻傳送獨立 group_id 訊息時,需監控系統通知欄快取壓力(建議單一裝置每小時 ≤30 則)。

四、總結

  • 輕量級需求: 優先使用 group_id 控制通知訊息折疊邏輯,開發成本低。
  • 高客製化需求: 選擇自訂訊息方案,透過用戶端程式碼實現全場景可控展示。
  • 混合策略: 對重要訊息(如付款成功)使用自訂訊息,一般通知建議使用 group_id 管理。

透過合理選擇方案,可顯著提升關鍵訊息的觸達率與使用者互動體驗。

Icon Solid Transparent White Qiyu
聯繫銷售