Saf*_*afa 2 android callback 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!!!!!!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
将NotificationReceivedHandler您的应用是否在前台才会触发.
如果您需要对收到的通知采取措施,无论您的应用程序状态如何,您都需要设置OneSingal NotificationExtenderService.
| 归档时间: |
|
| 查看次数: |
987 次 |
| 最近记录: |