gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:12:43 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com