How to Implement Push Notifications in Android (with Code)
June 22, 2025
.png)
.png)
Push notifications are a powerful tool for engaging users and delivering real-time updates in Android apps. In this blog, we’ll walk you through how to set up and implement push notifications using Firebase Cloud Messaging (FCM).
Importance of Push Notifications & Their Impact on User Experience
Push notifications play a crucial role in enhancing user engagement and overall app experience. Here's how:
- Real-Time Communication:
Push notifications allow apps to instantly inform users about important events like updates, offers, messages, or reminders, without them needing to open the app. - Improved User Engagement:
Timely and relevant notifications bring users back to the app, increasing retention and activity levels. - Personalisation:
Notifications can be tailored based on user behavior, preferences, or location, making the experience feel more relevant and personal. - Boosts Conversions:
For e-commerce, service, or booking apps, notifications about deals, abandoned carts, or limited-time offers often lead to higher conversion rates. - Better User Retention:
A well-designed notification strategy keeps users informed and involved, reducing app uninstalls and inactivity. - Operational Efficiency:
Notifications can be used for alerts (e.g., task updates, payment status, delivery tracking), helping users take timely action and improving satisfaction.
Step 1: Set Up Firebase Cloud Messaging (FCM)
1. Create a Firebase Project
- Go to the Firebase Console.
- Create a new project and register your Android app.
2. Add Firebase SDK
In your project-level build.gradle file:
3. Add google-services.json
- Download google-services.json from Firebase and place it in your app’s root directory (app/).
Step 2: Configure Permissions and Notification Channels
AndroidManifest.xml
Notification Channel (Android 8+)
Call this inside Application.onCreate().
Step 3: Receive and Handle Messages
Create a Firebase Messaging Service
Step 4: Send Push Notifications
Option 1: From Firebase Console
- Go to Firebase Console > Cloud Messaging > Send your first message
- Target your app and send!
Option 2: From Server (Using cURL or your backend)
Replace YOUR_SERVER_KEY with the one from Firebase > Project Settings > Cloud Messaging tab.
Step 5: Test and Debug
- Use adb logcat | grep FCM to see logs.
- Test with different Android versions to verify behavior.
- Use Firebase Notifications Composer to send test messages easily.
Best Practices
- Always use notification channels for Android 8.0+.
- Store the FCM token securely on your server.
- Show in-app messages only if the user is not already on the relevant screen.
- Use data-only messages if you want full control over behavior.
Conclusion
Integrating push notifications in Android with FCM is straightforward and powerful. Whether you're sending alerts, reminders, or messages, this setup ensures users stay engaged with your app.