DEV Community

Nguyễn Hữu Hiếu
Nguyễn Hữu Hiếu

Posted on

react native firebase fcm (firebase messaging cloud) + java spring boot: how to push notification

How to push FCM Notification with Java


  • Just use for data-only message
  • Need an extra field to contain id of notification
  • If use notification like normal => not have id
  • Want to custom notification
  • Send notification for quit + foreground + background
public class FcmTests {

    FirebaseMessaging firebaseMessaging;

    public void test1() throws FirebaseMessagingException {"FCM Sending...");

        List<String> registrationTokens = Collections.singletonList("<your fcm token here>");

        // iOS Config
        Aps aps = Aps.builder()
        ApnsConfig apnsConfig = ApnsConfig.builder()
        // android config
        AndroidConfig androidConfig = AndroidConfig.builder()

        MulticastMessage message = MulticastMessage.builder()
                .putData("title", "you can do everything")
                .putData("id", "1")
                .putData("body", "jumppp....")
        BatchResponse response = firebaseMessaging.sendMulticast(message);
        // See the BatchResponse reference documentation
        // for the contents of response."FCM Send success count=[{}]", response.getSuccessCount());

Enter fullscreen mode Exit fullscreen mode

Top comments (0)