Android - OneSignal 回调方法从未触发(notificationReceived - notificationOpened)

标签 android callback onesignal

我正在使用 onesignal 推送通知,它工作正常,但我遇到了“接收通知”的问题,因为我想在收到通知时采取行动。

这是我的代码,我按照文档进行操作,但一无所获。问题出在哪里?

public class MyApplication extends Application {
static Context context;
@Override public void onCreate() { 
  super.onCreate(); 
  context = getApplicationContext();


OneSignal.startInit(this) 
 .autoPromptLocation(true) 
 .setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())   
 .setNotificationReceivedHandler(new ExampleNotificationReceivedHandler())
 .init(); 
}

private class ExampleNotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {

@Override
public void notificationReceived(OSNotification notification) {
    Log.d("OneSignalExample", "notificationReceived!!!!!!");

}
}

  private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {

@Override
public void notificationOpened(OSNotificationOpenResult openedResult) {
    Log.d("OneSignalExample", "notificationOpened!!!!!!");

}
}
}

最佳答案

NotificationReceivedHandler仅当您的应用程序位于前台时才会触发。

如果您需要对收到的通知采取行动,而不管您的应用处于何种状态,您将需要设置一个 OneSingal NotificationExtenderService相反。

关于Android - OneSignal 回调方法从未触发(notificationReceived - notificationOpened),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40384957/

相关文章:

android - 如何在使用 Android 中的自定义数组适配器在 ListView 中使用复选框选中后删除多个项目?

java - 来自 logcat 调试的致命信号 11 (SIGSEGV) 位于 0x00000000(代码=1)

jquery - 重写 JavascriptConfirm() 同时保留回调

android - OneSignal 导致 Google Play 服务版本发生变化

java - Android 如何使用 Caldroid Lib 中异步任务的数据填充日历

javascript - Node 异步数组循环结果不符合预期

node.js - Nodejs 异步函数回调错误的执行顺序

android - Cordova/PhoneGap Android 混合移动应用程序中无法加载任何插件。怎么解决?

ios - 通知警报禁用 swift

java - Eval() 解释器返回 null