Setting Up Android Push Notifications

Setting Up Android Push Notifications with Firebase Cloud Messaging (FCM)

Overview

This guide provides step-by-step instructions to set up Android Push Notifications using Firebase Cloud Messaging (FCM). By following these steps, users can enable push notifications in their Android app and integrate FCM for seamless message delivery.


Prerequisites

Before proceeding, ensure you have:

  • An active Google account.

  • Android Studio installed on your system.

  • A Firebase project set up in the Firebase Console.

  • A registered Android app in Firebase.


Step 1: Create a Firebase Project

  1. Click Add Project.

  2. Enter your project name and click Continue.

  3. Click Create Project and wait for the setup to complete.


Step 2: Register Your Android App in Firebase

  1. In Firebase Console, open your project.

  2. Click the Settings (⚙️) > Project Settings.

  3. Under the General tab, scroll to Your Apps.

  4. Click Add App > Android.

  5. Enter your Android package name (from AndroidManifest.xml).

  6. (Optional) Add an App Nickname.

  7. Click Register App.


Step 3: Download and Add google-services.json

  1. After registering the app, click Download google-services.json.

  2. Move this file to your Android project:

  • Place it in the app/ directory.

  1. Open your project’s build.gradle files and ensure Firebase dependencies are added:

  • Project-level build.gradle (android/build.gradle):

dependencies {

dependencies {
    classpath 'com.google.gms:google-services:4.3.10'
}
  • App-level build.gradle (android/app/build.gradle):

apply plugin: 'com.google.gms.google-services'

Step 4: Add Firebase Cloud Messaging (FCM) SDK

  1. Open app/build.gradle.

  2. Add the following dependency:

dependencies {

dependencies {
    implementation 'com.google.firebase:firebase-messaging:23.1.0'
}
  1. Sync your Gradle files.


Step 5: Implement Push Notification Handling

Enable Notifications in AndroidManifest.xml

Add the following permissions inside the <manifest> tag:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Create a Firebase Messaging Service

  1. Create a new Java/Kotlin class MyFirebaseMessagingService.

  2. Extend FirebaseMessagingService and override onMessageReceived():

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if (remoteMessage.getNotification() != null) {
            Log.d("FCM", "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }
    }
}
  1. Register this service in AndroidManifest.xml:

<service android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

Step 6: Test Push Notifications

Obtain Firebase Cloud Messaging Token

  1. In MyFirebaseMessagingService, add the following:

@Override
public void onNewToken(String token) {
    Log.d("FCM", "Refreshed token: " + token);
}
  1. Run your app and check Logcat for the FCM token.

  2. Copy the token for testing.

Send a Test Notification from Firebase Console

  1. Go to Firebase Console > Cloud Messaging.

  2. Click Send your first message.

  3. Enter a notification title and message.

  4. Select Send to a test device.

  5. Paste the copied FCM token.

  6. Click Send Message and check if the notification appears on the device.


Step 7: Configure Firebase in Organon

To send notifications from Organon, users must upload their google-services.json file.

  1. Open Organon and go to Push Notification Settings.

  2. Navigate to the Android tab.

  3. Click Edit and upload the google-services.json file(present inside general settings of firebase ,select your app and download google-services.json file ).

  4. Save the configuration.

  5. Enable Android Push Configuration.

  6. Send a test notification to confirm setup.


Step 8: Deploy and Monitor Push Notifications

Once testing is successful:

  • Use Organon’s campaign feature to send push notifications.

  • Monitor delivery rates and engagement using Organon’s analytics dashboard.

  • Optimize message content for better user interaction.


Troubleshooting

  • Ensure google-services.json is correctly placed in Organon’s settings.

  • Verify the Firebase project is set to allow push notifications.

  • Check Organon’s notification logs for errors.

  • Ensure the device has internet connectivity.

Following these steps will enable push notifications via Firebase Cloud Messaging and allow sending notifications directly from Organon.

Last updated