我正在使用 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/