Push Messaging

Send push notifications to an Android app

Write a message in your browser and send it as a push notification to an Android app running next to it. Try notification and data payloads and see how the app handles each one.

The Mobile Push demo: an Android phone showing a notification from PubNub, next to the message form and the pn_fcm payload it publishes
About this demo

One publish, delivered by FCM

The demo has two parts. The sender is a web page built with the PubNub JavaScript SDK. The receiver is an Android app written in Kotlin with the PubNub Kotlin SDK and Firebase Cloud Messaging (FCM). It runs in a hosted Android emulator inside the demo.

When the app starts, it gets an FCM token and registers it on the push-demo channel. The web page then publishes a normal PubNub message with a pn_fcm key. PubNub's Push Gateway sees that key and forwards the message to FCM for every device registered on the channel. There's no push server of your own. The demo covers Android only. The Android app's source is on GitHub, and the tutorial walks you through adding push to your own app.

Features

What you can do

  • Launch the Android app

    Start the app in the emulator beside the form. It asks for notification permission, gets its FCM token, and registers the token on the push-demo channel.

  • Write your message

    Enter a title and a body. The page shows the exact pubnub.publish() call it will make, and updates it as you type.

  • Send a notification payload

    With the app open, the message appears as a snackbar inside the app. Put the app in the background and Android shows it as a system notification.

  • Send a data payload

    The app handles data messages itself and always posts a notification, whether it is in the foreground or the background. Select both types to send them together.

  • Push with a plain publish

    The sender only publishes to a channel. The pn_fcm key tells PubNub to forward the message to FCM for each device token registered on that channel.

Build it yourself

Add push notifications to your app

Follow the tutorial to add mobile push to your own app, or clone the Android receiver and run it with your own keys.

Tutorial

Mobile Push Notifications Tutorial

Connect your keyset to FCM and APNs, register device tokens on channels, and publish messages with push payloads.

GitHub

PubNubDevelopers/push-mobile-demo

The Android receiver app. Add your Firebase google-services.json and your PubNub subscribe key, build it in Android Studio, then publish a pn_fcm message to the push-demo channel.

git clone https://github.com/PubNubDevelopers/push-mobile-demo.git
View on GitHub
Keep building

Build interactive real-time experiences with PubNub

Bring chat, live updates, and real-time interactions into your application without building the infrastructure from scratch.