NotificationExtenderService 未触发 handleNotificationReceived

NotificationExtenderService not firing handleNotificationReceived

我正在 Java class 内扩展 NotificationExtenderService 根据此处的 OneSignal 文档 One signal doc,但我意识到返回 true 会阻止显示通知。到目前为止很完美,问题是我仍然需要在我的打字稿代码中触发 handleNotificationReceived

下面是 Java 代码扩展:

public class NotificationExtenderBareBonesExample extends NotificationExtenderService {
@Override
protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
    receivedResult.payload.lockScreenVisibility = Integer.parseInt("-1");
    JSONObject data = receivedResult.payload.additionalData;
    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.
            builder = builder.setVisibility(Integer.parseInt("-1"));
            builder = builder.setVibrate(new long[]{0L});
            return builder.setColor(new BigInteger("800d2f66", 16).intValue());
        }
    };
    OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
    Log.d("OneSignalExample", "Notification displayed with id: " + displayedResult.androidNotificationId);
    return true;
}

}

我遇到的问题是我需要调用 displayNotification 来触发我的 NotificationReceivedHandler(它会相应地分析 additionalData 和 运行 部分)。

离子 2 代码:

this.oneSignal.handleNotificationReceived().subscribe((result) => {
  alert('received ' + JSON.stringify(result));
  thisRef.writeDebug('notification received');
  let data = result.payload.additionalData;
  let chatmessage = "";
  if (data != null) {
      if(typeof data !== 'undefined' && data.length != 0)
      {
        if(typeof data.chatmessage !== 'undefined')
          console.log('chatmessage ok');
        if(typeof data.id !== 'undefined')
          thisRef._callbackOnChatMessage({chatmessage: data.chatmessage, id: data.id.toString()})
        if(typeof data.shortgeolocation !== 'undefined')
        {
          this._callbackRequestShortLocation(data.shortgeolocation);
        }
      }
      if(typeof data.othertyping !== 'undefined' && typeof thisRef._callbackOnOtherTyping !== 'undefined')
      {
        thisRef._callbackOnOtherTyping(data.othertyping);
      }
  }
});

这是我的通知到达我的 Ionic 处理程序后的预览:

有什么方法可以将 displayTypeShown 的值分别更改为 NotificationExtenderService 中的 0 和 false 以便调用我在 Ionic 中的 NotificationReceivedHandler 并且不显示警报? (我在 iOS 下得到了这种行为,在 Android 中努力做到这一点)。

已部分解决,我不得不将 onesignal 库降级到 3.5.6 在 platforms/android.properties 中,使用 cordova.system.library.[keep your number x]=com.onesignal:OneSignal:3.5.6 解决了这个问题。 对于 ionic,文件位于 platforms/android/

this post 绝对相关。

我收到一封来自 OneSignal 的邮件,说明版本 3.6.2 正在解决这个问题。 所以 Android 属性 现在应该是 com.onesignal:OneSignal:3.6.2。 请参阅我更新的文件更新问题。