A complete end-to-end Firebase Cloud Messaging (FCM) push notification system with Python Flask backend and Android client.
- Python Backend with Flask and Firebase Admin SDK
- Android App with FCM integration and modern UI
- Real-time Push Notifications from server to device
- RESTful API for notification management
- Device Token Management with registration system
- Sample Notification Content for demonstration
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Android App βββββΊβ Python Backend βββββΊβ Firebase Cloud β
β β β (Flask API) β β Messaging β
β β’ FCM Token β β β’ Admin SDK β β β
β β’ Notifications β β β’ Device Tokens β β β’ Push Service β
β β’ UI Interface β β β’ Sample Data β β β’ Delivery β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
- Generate FCM Token - Android app creates unique device identifier
- Register Device - App sends token to backend server
- Send Notification - Server uses Firebase Admin SDK to push notification
- Receive & Display - Android app shows notification to user
- Python 3.7+
- Android Studio
- Firebase Project with Admin SDK key
- Android device/emulator
-
Clone the repository:
git clone https://github.com/Varnika-k/fcm-push-notification-system.git cd fcm-push-notification-system -
Install Python dependencies:
pip install -r requirements_simple.txt
-
Configure Firebase:
- Get Firebase Admin SDK key from Firebase Console
- Update
.envfile with path to your key:FIREBASE_SERVICE_ACCOUNT_KEY=path/to/your/firebase-key.json
-
Start the server:
python app_simple.py
Server runs on
http://localhost:5000
-
Get Firebase configuration:
- In Firebase Console, add Android app with package
com.example.fcmdemo - Download
google-services.json - Place in
android_app/app/google-services.json
- In Firebase Console, add Android app with package
-
Open in Android Studio:
- Open
android_appfolder - Let Gradle sync complete
- Build and run on device/emulator
- Open
-
Test the flow:
- Click "Get FCM Token"
- Click "Register with Server"
- Click "Send Test Notification"
- Check notification tray! π
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Server status and available endpoints |
GET |
/notifications |
Fetch sample notification content |
GET |
/devices |
List registered devices |
POST |
/register-device |
Register FCM token |
POST |
/send-notification |
Send push notification |
curl -X POST http://localhost:5000/register-device \
-H "Content-Type: application/json" \
-d '{
"fcm_token": "device_fcm_token_here",
"device_id": "android_demo_device"
}'curl -X POST http://localhost:5000/send-notification \
-H "Content-Type: application/json" \
-d '{
"notification_id": 1,
"title": "Custom Title",
"body": "Custom message"
}'fcm-push-notification-system/
βββ README.md # This file
βββ app_simple.py # Flask backend server
βββ requirements_simple.txt # Python dependencies
βββ .env # Environment configuration
βββ test_system.py # System testing script
βββ .gitignore # Git ignore rules
βββ START_HERE.md # Quick start guide
βββ ANDROID_SETUP_GUIDE.md # Android setup instructions
βββ SETUP_INSTRUCTIONS.md # Detailed setup guide
βββ android_app/ # Complete Android project
βββ app/
β βββ build.gradle # Android dependencies
β βββ google-services.json.template # Firebase config template
β βββ src/main/
β βββ AndroidManifest.xml
β βββ java/com/example/fcmdemo/
β β βββ MainActivity.java # Main app activity
β β βββ FCMService.java # FCM service handler
β βββ res/ # Android resources
βββ build.gradle # Project-level Gradle
βββ settings.gradle # Gradle settings
# Firebase Configuration
FIREBASE_SERVICE_ACCOUNT_KEY=path/to/firebase-key.json
# Server Configuration
FLASK_PORT=5000
FLASK_DEBUG=True- Package Name:
com.example.fcmdemo - Firebase Config:
google-services.jsoninapp/folder - Server URL: Configure in
MainActivity.java- Emulator:
http://10.0.2.2:5000 - Real device:
http://YOUR_IP:5000
- Emulator:
- Modern Material Design UI with CardView components
- FCM Token Generation with error handling
- Server Registration with HTTP client
- Push Notification Reception with custom service
- Permission Handling for Android 13+ notifications
- Real-time Status Updates with user feedback
- Flask REST API with CORS support
- Firebase Admin SDK Integration for FCM
- In-memory Token Storage (easily extendable to database)
- Sample Notification Content for demonstration
- Error Handling with detailed logging
- Development Server with hot reload
- Firebase Keys Protected - Never committed to repository
- Environment Variables for sensitive configuration
- Input Validation on API endpoints
- Error Handling without exposing internals
Test Backend:
python test_system.pyTest API Endpoints:
# Server status
curl http://localhost:5000/
# Sample notifications
curl http://localhost:5000/notifications
# Registered devices
curl http://localhost:5000/devices| Problem | Solution |
|---|---|
| Firebase not initialized | Check firebase key path in .env |
| Android app crashes | Ensure google-services.json exists |
| No notifications received | Check device notification permissions |
| Server connection failed | Update server URL in Android app |
- Database Integration (PostgreSQL/MongoDB)
- User Authentication and authorization
- Notification History and analytics
- Scheduled Notifications with cron jobs
- Notification Templates and personalization
- Web Dashboard for notification management
- Multiple Device Support per user
- Push Notification Analytics and metrics
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Firebase for Cloud Messaging service
- Flask for Python web framework
- Android Firebase SDK team
- Material Design for UI components
For support and questions:
- Open an Issue
- Check Documentation
- Review Setup Guides
β Star this repository if it helped you build FCM push notifications!
π Ready to send your first push notification? Follow START_HERE.md