I'm sending push notifications using the Firebase Admin Java SKD and in my Ionic app I'm using the phonegap-plugin-push.
My problem is that when my app is in background the function push.on('notification', function(data) {} is not called. I guess it's the problem mentioned here. The problem only happens on Android devices, on iOS devices the notification function is called without problems, even when the application is in background.
The solution says that we have to set "content-available" to 1 in order to the force the function to be called.
The class com.google.firebase.messaging.Aps exposes the properties content-available but I can't find the same in the class AndroidNotification.
How can I send the property "content-available" along with the payload in Android? And is that really the problem? Why doesn't iOS need this property?
This is the code I'm using to send the notification:
AndroidConfig androidConfig = AndroidConfig.builder()
.setTtl(Duration.ofMinutes(2).toMillis()).setCollapseKey("key")
.setPriority(Priority.HIGH)
.setNotification(AndroidNotification.builder().setTag("tag").build()).build();
ApnsConfig apnsConfig = ApnsConfig.builder()
.setAps(Aps.builder().setCategory("category").setThreadId("thread").build()).build();
Message message = Message.builder().putAllData(data).setTopic("topic")
.setApnsConfig(apnsConfig).setAndroidConfig(androidConfig)
.setNotification(
new Notification("Title", "Message"))
.build();
String response = FirebaseMessaging.getInstance().sendAsync(message).get();