OneSignal Silent (Background) Notifications in Android


I’ve successfully moved from Ionic push to OneSignal and I must say the transition was smooth and the integration is very easy. I’m using the OneSignal native plugin from Ionic.

Notifications work just fine, but my problem is with silent notifications. I use them to notify something to the app that you don’t want to display to the user (usually, this kind of notifications has no text content). In Ionic push, silent notifications were sent by setting the field content_available=1 in the push API, and work just fine in Android. If you are in the app, you can listen for the event, but outside the app, the notification is not displayed to the user.

In OneSignal, there is also a content_available (bool) property you can send in the API, but apparently it only works on iOS. In fact, the notification is displayed to the user, with no content (just the title), even with the app opened (something that doesn’t occur with regular notifications as they are handled)

I’ve read lot of posts about it, and there is also a recommendation from OneSignal official site:

The thing is that all of them require to modify the java plugin code.

Currently, I’m sending my notification with some dummy content so it is not displayed to the user. As far as I’m with the app opened I have no problem because I manage the event. The thing is if I close the app and the notification arrives later, it is displayed to the user with the dummy content.