簡體   English   中英

如何使用 OneSignal 從靜默推送通知中獲取消息?

[英]How to get a message from a silent Push notification with OneSignal?

在某些情況下,我需要發送一些消息並在后台做一些事情,我在 OneSignal 的文檔中找到了這個例子,它展示了如何設置,但我看不到我將如何獲得它發送的消息!

public class NotificationExtenderBare extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
    OverrideSettings overrideSettings = new OverrideSettings();
    overrideSettings.extender = new NotificationCompat.Extender() {
        @Override
        public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {

            // Sets the background notification color to Green on Android 5.0+ devices.
            return builder.setColor(new BigInteger("FF00FF00", 16).intValue());
        }
    };

    OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
    // Read properties from result.

    // Return true to stop the notification from displaying.
    return true;

謝謝你的提問。 我將更新文檔以使其更加清晰。

您可以使用receivedResult.payload獲取消息

這是OSNotificationReceivedResult的類定義

public class OSNotificationReceivedResult {
   public boolean restoring;

   public boolean isAppInFocus;

   public OSNotificationPayload payload;
}

編輯:更新的文檔更清晰,帶有示例代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM