'Java Firebase API: Notification vs WebpushNotification

The core class of the firebase java API is the Message / MulticastMessage class. MulticastMessage contains a Notification object and a WebpushConfig object. Should these be interchangeable in an either/or sense?

I have some code that creates a Notification, uses the Notification to create a message, adds my firebase token to the message, and sends the message. This shows up as a notification to the phone identified by my token.

    Notification notification = Notification
            .builder()
            .setTitle(pushData.getSubject())
            .setBody(pushData.getContent())
            .build();

    MulticastMessage message = MulticastMessage
            .builder()
            .addAllTokens(tokens)
            .setNotification(notification)
            .putAllData(pushData.getData())
            .build();

    BatchResponse response = firebaseMessaging.sendMulticast(message);

But I need the ability to generate silent notifications. WebpushNotification provides the setSilent(true) method. So I tried simply replacing the Notification with a WebpushConfig. Firebase accepts the message, but does not generate a notification to the phone identified with my token.

    WebpushNotification notification = WebpushNotification.builder()
            .setTitle(pushData.getSubject())
            .setBody(pushData.getContent())
            .setSilent(false)
            .build();
    WebpushConfig webpush = WebpushConfig.builder()
            .setNotification(notification)
            .putAllData(pushData.getData())
            .build();

    MulticastMessage message = MulticastMessage
            .builder()
            .addAllTokens(tokens)
            .setWebpushConfig(webpush)
            .build();

    BatchResponse response = firebaseMessaging.sendMulticast(message);

Is this not the purpose of WebpushConfig? If not, how do I go about sending a silent notification with the Java API?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source