Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent alert with incoming OneSignal notification?

I use OneSignal push notifications. When android app is in foreground and receives a notification, it creates an alert box with the notification. How to prevent this from appearing when receiving notifications?

like image 624
user3671635 Avatar asked Dec 16 '16 11:12

user3671635


People also ask

How do I stop getting push notices?

Open your phone's Settings app. Notifications. Under "Lock screen," tap Notifications on lock screen or On lock screen. Choose Don't show notifications.

What is silent push notification?

Users can choose to mute their notifications and receive silent push notifications instead of being alerted to every new push that arrives. They can activate this on iOS or Android from their individual settings pages. And developers or mobile marketers cannot override this setting once put into place.

How do I send silent push notifications?

To send a Silent Push Notification to your mobile app, check the checkbox Silent Push in the iOS and Android push settings of the Send Push form.


1 Answers

It's changed in OneSignal 4.0.

For Kotlin:

OneSignal.setNotificationWillShowInForegroundHandler { notificationReceivedEvent ->
    notificationReceivedEvent.complete(null)
}

For Java:

OneSignal.setNotificationWillShowInForegroundHandler(new NotificationWillShowInForegroundHandler() {
  @Override
  void notificationWillShowInForeground(OSNotificationReceivedEvent notificationReceivedEvent) {    
     notificationReceivedEvent.complete(null);
  }
});
like image 114
Muz Avatar answered Oct 10 '22 15:10

Muz