Reputation: 473
I'm using onesignal to push notification and it works fine but i faced an issue with "Receiving Notifications" since i want to take an action when receive the notification.
here's my code, i follow the documentation but i got nothing. where's the issue?
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!!!!!!");
}
}
}
Upvotes: 2
Views: 1795
Reputation: 3948
The NotificationReceivedHandler
will only fire if your app is in the foreground.
If you need to take action on a received notification regardless of your app's state you will need to setup a OneSingal NotificationExtenderService
instead.
Upvotes: 6
Reputation: 325
Quoting directly from the documentation
By default OneSignal will open or resume your launcher Activity when a notification is tapped on. You can disable this behavior by adding the meta-data tag com.onesignal.NotificationOpened.DEFAULT set to DISABLE inside your application tag in your AndroidManifest.xml
Upvotes: 0