Skip to main content
Threadly uses Firebase Cloud Messaging (FCM) to deliver real-time push notifications when users receive messages, likes, comments, and other interactions while offline.

Why Firebase?

Threadly’s messaging system uses Socket.IO for real-time communication. However, when the app is in the background or closed, Firebase Cloud Messaging acts as a fallback to ensure users never miss important notifications.
Hybrid Notification System
  • Socket.IO handles real-time delivery when app is active
  • FCM delivers notifications when app is backgrounded or closed

Create a Firebase Project

1

Go to Firebase Console

Visit console.firebase.google.com and sign in with your Google account.
2

Create a new project

  • Click Add project
  • Enter a project name (e.g., “Threadly”)
  • Click Continue
3

Configure Google Analytics (optional)

  • Choose whether to enable Google Analytics
  • Select an Analytics account or create a new one
  • Click Create project
4

Wait for project creation

Firebase will set up your project. This takes a few seconds.

Add Android App to Firebase

1

Add an Android app

From your Firebase project dashboard:
  • Click the Android icon to add an Android app
  • Or go to Project settings > General > Your apps
2

Register your app

Fill in the required information:
FieldValue
Android package namecom.rtech.threadly
App nicknameThreadly (optional)
Debug signing certificate SHA-1Optional for development
The package name must exactly match the applicationId in your app/build.gradle file.
3

Download google-services.json

  • Click Download google-services.json
  • Save the file - you’ll need it in the next section
4

Skip the SDK setup steps

Threadly already has Firebase dependencies configured. Click Next through the remaining steps and Continue to console.

Add google-services.json to Project

1

Locate the app directory

In your Threadly project, find the app/ directory:
threadly/
├── app/
│   ├── src/
│   ├── build.gradle
│   └── google-services.json  ← Place file here
├── build.gradle
└── settings.gradle
2

Copy google-services.json

Copy the downloaded google-services.json file to the app/ directory (same level as app/build.gradle).
cp ~/Downloads/google-services.json /path/to/threadly/app/
3

Verify file placement

In Android Studio, you should see google-services.json under the app module in Project view:
app
├── manifests
├── java
├── res
├── google-services.json  ✓
└── build.gradle
4

Sync Gradle

Click Sync Now when prompted, or manually sync:
  • Windows/Linux: Ctrl + Shift + O
  • macOS: Cmd + Shift + O
Never commit google-services.json to public repositories!Add it to your .gitignore if your repository is public:
.gitignore
app/google-services.json

Verify Firebase Integration

Threadly already includes the necessary Firebase dependencies and configuration:

Gradle Plugin

build.gradle (Project level)
plugins {
    alias(libs.plugins.google.gms.google.services) apply false
}
app/build.gradle
plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.google.gms.google.services)
}

Firebase Messaging Dependency

app/build.gradle
dependencies {
    implementation libs.firebase.messaging
}

FCM Service Implementation

Threadly includes a custom FCM service:
AndroidManifest.xml
<service
    android:name=".services.FcmService"
    android:exported="true">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>
If you’ve followed all steps, Firebase is now fully integrated!

Enable Cloud Messaging API

1

Navigate to Cloud Messaging

In Firebase Console:
  • Go to Project settings > Cloud Messaging
  • Or directly visit: https://console.firebase.google.com/project/YOUR_PROJECT/settings/cloudmessaging
2

Enable Cloud Messaging API

  • Click Enable if the API is not yet enabled
  • Note down your Server Key and Sender ID for backend configuration

Configure Backend for FCM

Your backend server needs Firebase Admin SDK credentials to send push notifications:
1

Generate a private key

In Firebase Console:
  1. Go to Project settings > Service accounts
  2. Click Generate new private key
  3. Confirm and download the JSON file
2

Add to backend

In your backend repository (threadlyServer):
  1. Save the JSON file as serviceAccountKey.json
  2. Add it to your .env or backend configuration
  3. Initialize Firebase Admin SDK:
server.js
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});
Keep your service account key secure! Never commit it to version control or expose it publicly.

Test Push Notifications

1

Run the app

Build and launch Threadly on your device or emulator.
2

Check FCM token generation

Open Logcat and filter for:
tag:FCM OR tag:FcmService
You should see logs indicating FCM token generation.
3

Send a test notification

From Firebase Console:
  1. Go to Cloud Messaging > Send your first message
  2. Enter a notification title and text
  3. Click Send test message
  4. Enter your FCM token (from Logcat)
  5. Click Test
4

Verify notification delivery

  • Background the app or close it completely
  • You should receive a push notification
  • Tap it to open the app

Notification Permissions

Threadly requests notification permission at runtime (required for Android 13+):
AndroidManifest.xml
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Users must grant this permission for push notifications to work.
Best Practice: Request notification permission after the user signs in or when they’re about to receive their first message. This provides better context and improves permission grant rates.

Troubleshooting

  • Ensure file is in app/ directory, not app/src/
  • File name must be exactly google-services.json (case-sensitive)
  • Perform a Gradle sync after adding the file
  • Try File > Invalidate Caches / Restart
  • Check internet connection
  • Verify google-services.json matches your package name
  • Check Logcat for Firebase initialization errors
  • Ensure Firebase Messaging dependency is included
  • Verify POST_NOTIFICATIONS permission is granted
  • Check device battery optimization settings
  • Ensure app is registered with FCM (check Logcat for token)
  • Verify backend has correct Firebase Admin SDK configuration
  • Test with Firebase Console test message first
This usually indicates version conflicts. Ensure consistent Firebase versions:
libs.versions.toml
[versions]
firebase-bom = "32.7.0"

[libraries]
firebase-messaging = { module = "com.google.firebase:firebase-messaging", version.ref = "firebase-bom" }

FCM Service Customization

Threadly’s FCM service is located at:
app/src/main/java/com/rtech/threadly/services/FcmService.java
You can customize notification behavior, handling, and appearance by editing this file.

Next Steps

Setup Complete! You now have a fully configured Threadly development environment.

Architecture Overview

Learn about Threadly’s MVVM architecture

API Reference

Explore the backend API integration

Build docs developers (and LLMs) love