logo
產品文件
搜尋

如何實現訊息不折疊展示

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

alt text

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

通知訊息(Notification)

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

自訂訊息(Custom Message)

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

  • 適用情境:
    需高度自訂互動的高優先級訊息(如訂單狀態提醒、即時聊天)。

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

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

(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 在背景,訊息展示仍受系統限制。

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

實現原理

透過客戶端主動呼叫 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
聯繫銷售