Skip to content

Varnika-k/getto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”” FCM Push Notification System

A complete end-to-end Firebase Cloud Messaging (FCM) push notification system with Python Flask backend and Android client.

🎯 Features

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Android App   │◄──►│  Python Backend  │◄──►│ Firebase Cloud  β”‚
β”‚                 β”‚    β”‚   (Flask API)    β”‚    β”‚   Messaging     β”‚
β”‚ β€’ FCM Token     β”‚    β”‚ β€’ Admin SDK      β”‚    β”‚                 β”‚
β”‚ β€’ Notifications β”‚    β”‚ β€’ Device Tokens  β”‚    β”‚ β€’ Push Service  β”‚
β”‚ β€’ UI Interface  β”‚    β”‚ β€’ Sample Data    β”‚    β”‚ β€’ Delivery      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“± Demo Flow

  1. Generate FCM Token - Android app creates unique device identifier
  2. Register Device - App sends token to backend server
  3. Send Notification - Server uses Firebase Admin SDK to push notification
  4. Receive & Display - Android app shows notification to user

πŸš€ Quick Start

Prerequisites

  • Python 3.7+
  • Android Studio
  • Firebase Project with Admin SDK key
  • Android device/emulator

Backend Setup

  1. Clone the repository:

    git clone https://github.com/Varnika-k/fcm-push-notification-system.git
    cd fcm-push-notification-system
  2. Install Python dependencies:

    pip install -r requirements_simple.txt
  3. Configure Firebase:

    • Get Firebase Admin SDK key from Firebase Console
    • Update .env file with path to your key:
      FIREBASE_SERVICE_ACCOUNT_KEY=path/to/your/firebase-key.json
      
  4. Start the server:

    python app_simple.py

    Server runs on http://localhost:5000

Android Setup

  1. 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
  2. Open in Android Studio:

    • Open android_app folder
    • Let Gradle sync complete
    • Build and run on device/emulator
  3. Test the flow:

    • Click "Get FCM Token"
    • Click "Register with Server"
    • Click "Send Test Notification"
    • Check notification tray! πŸŽ‰

πŸ“š API Documentation

Endpoints

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

Register Device

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"
  }'

Send Notification

curl -X POST http://localhost:5000/send-notification \
  -H "Content-Type: application/json" \
  -d '{
    "notification_id": 1,
    "title": "Custom Title",
    "body": "Custom message"
  }'

πŸ—‚οΈ Project Structure

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

πŸ”§ Configuration

Backend Configuration (.env)

# Firebase Configuration
FIREBASE_SERVICE_ACCOUNT_KEY=path/to/firebase-key.json

# Server Configuration  
FLASK_PORT=5000
FLASK_DEBUG=True

Android Configuration

  • Package Name: com.example.fcmdemo
  • Firebase Config: google-services.json in app/ folder
  • Server URL: Configure in MainActivity.java
    • Emulator: http://10.0.2.2:5000
    • Real device: http://YOUR_IP:5000

πŸ“± Android App Features

  • 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

πŸ–₯️ Backend Features

  • 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

πŸ” Security Features

  • Firebase Keys Protected - Never committed to repository
  • Environment Variables for sensitive configuration
  • Input Validation on API endpoints
  • Error Handling without exposing internals

πŸ§ͺ Testing

Test Backend:

python test_system.py

Test API Endpoints:

# Server status
curl http://localhost:5000/

# Sample notifications
curl http://localhost:5000/notifications

# Registered devices
curl http://localhost:5000/devices

🚨 Troubleshooting

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

πŸ“ˆ Future Enhancements

  • 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

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Firebase for Cloud Messaging service
  • Flask for Python web framework
  • Android Firebase SDK team
  • Material Design for UI components

πŸ“ž Support

For support and questions:


⭐ Star this repository if it helped you build FCM push notifications!

πŸš€ Ready to send your first push notification? Follow START_HERE.md

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors