Ved
Ved

Reputation: 1077

Stop OneSignal notification to display in status bar

I have implemented OneSignal and successfully sending notification to my android app, but I want to discard some notification based on additional data received in push notification. How can I discard notification before displaying in status bar.

Upvotes: 3

Views: 2740

Answers (1)

Vishnu Prasad
Vishnu Prasad

Reputation: 556

To do so create a class which extends NotificationExtenderService,

In this

import com.onesignal.OSNotificationPayload;
import com.onesignal.NotificationExtenderService;

public class NotificationExtenderBareBonesExample extends NotificationExtenderService {
   @Override
   protected boolean onNotificationProcessing(OSNotificationPayload notification) {
      // Read any properties you need from notification.
      // Return true if you want to keep a notification from displaying else return false if you dont want to display notification.
      return false;
   }
}

Also when sending notification from panel check the Background data checkbox

And edit your manifest file to include this:-

<service
   android:name=".YOUR_CLASS_NAME"
   android:exported="false">
   <intent-filter>
      <action android:name="com.onesignal.NotificationExtender" />
   </intent-filter>
</service>

Upvotes: 4

Related Questions