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.
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.