If youโve ever wanted to send real-time notifications to your Android users, Firebase Cloud Messaging (FCM) is the most reliable and free solution. In this blog, weโll explore what FCM is, how it works, and provide a step-by-step implementation guide with code examples.
๐น What is Firebase Cloud Messaging (FCM)?
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you send notifications and data messages to Android, iOS, and web apps at no cost.
With FCM, you can:
- Send push notifications from Firebase Console or server.
- Deliver custom messages (JSON payload).
- Notify users about new updates, chat messages, promotions, or reminders.
- Handle background and foreground messages seamlessly.
๐น How FCM Works
- Your App requests a unique FCM Registration Token.
- Firebase Server generates and assigns a token to your device.
- You (or your backend) send a push message to that token using FCM APIs.
- The Android device receives and displays the notification.
๐น Step 1: Setup Firebase in Your Project
- Go to Firebase Console.
- Create a new project or select an existing one.
- Add an Android app package name.
- Download the
google-services.json
file and place it in your app folder (app/
). - In
settings.gradle
:
- In
app/build.gradle
:
๐น Step 2: Get the FCM Token
In your MainActivity.kt
:
๐น Step 3: Handle Incoming Messages
Create a service class:
Add service to AndroidManifest.xml
:
๐น Step 4: Send a Test Notification
- Open Firebase Console โ Cloud Messaging โ Send your first message.
- Enter a title & body.
- Choose target app package.
- Click Send.
- Check your Android device โ you should see the notification ๐.
๐น Step 5: Advanced Features
- Custom Data Payload (JSON for chat apps).
- Topic Messaging (send to groups of users).
- Device Groups (family/shared devices).
- Silent Push Notifications (for background sync).
โ Conclusion
Firebase Cloud Messaging is one of the best free tools for engaging users with real-time updates. Whether youโre building a chat app, e-commerce store, or news app, FCM provides a reliable and scalable push notification solution.
๐ With just a few lines of code, you can send, receive, and display notifications in your Android app.