如何使用OneSignal从静默的推送通知中获取消息?

时间:2019-01-27 13:22:40

标签: java 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;

1 个答案:

答案 0 :(得分:0)

感谢您的提问。我将更新文档以使其更加清晰。

您可以使用receivedResult.payload

来获取消息

这是OSNotificationReceivedResult

的类定义
public class OSNotificationReceivedResult {
   public boolean restoring;

   public boolean isAppInFocus;

   public OSNotificationPayload payload;
}

编辑:使用示例代码将docs更新为更加清晰