Complete Guide to Setting Up and Integrating OneSignal in Your Android App Using Firebase

If you’re developing an Android application and want to implement push notifications, OneSignal is one of the most efficient services available. This article provides a step-by-step guide on how to integrate OneSignal with Firebase and configure your Android project to send push notifications effectively.


Step 1: Create and Set Up Your Firebase Project

  1. Visit the official Firebase Console: https://console.firebase.google.com/.
  2. Click on “Add Project” and enter your project name.
  3. Accept the terms and click “Create Project”.
  4. Once your project is created, click “Continue” to enter the Firebase project dashboard.

Step 2: Register Your Android App in Firebase

  1. In the Firebase dashboard, click the Android icon to register your app.
  2. Enter your app’s package name (you can find it in your app’s AndroidManifest.xml).
  3. (Optional) Provide a nickname and SHA-1 key if needed.
  4. Click “Register App”.

Step 3: Download and Add google-services.json File

  1. After registration, download the google-services.json file.
  2. Move this file into your app’s app/ directory in Android Studio.

Step 4: Configure Your Android Project for Firebase

  1. In your project-level build.gradle, add the following classpath:
classpath 'com.google.gms:google-services:4.3.15' // or latest version
  1. In your app-level build.gradle, apply the plugin at the bottom:
apply plugin: 'com.google.gms.google-services'
  1. Sync your project to ensure the Firebase SDK is added.

Step 5: Enable Firebase Cloud Messaging (FCM)

  1. Go to Project Settings > Cloud Messaging in Firebase.
  2. Ensure that Cloud Messaging API (Legacy) is enabled.
  3. Copy the Server Key and Sender ID—you will need these for OneSignal.

Step 6: Set Up Your OneSignal Account

  1. Visit https://onesignal.com/ and sign up or log in.
  2. Click “New App/Website” and give it a name.
  3. Choose “Google Android” as the platform.
  4. Paste your Firebase Server Key and Sender ID when prompted.
  5. Click “Save & Continue”.

Step 7: Integrate OneSignal in Your Android App

  1. In your app-level build.gradle, add the OneSignal dependency:
implementation 'com.onesignal:OneSignal:[4.8.5, 4.99.99]'
  1. In the onCreate() method of your Application class, initialize OneSignal:
OneSignal.initWithContext(this);
OneSignal.setAppId("YOUR-ONESIGNAL-APP-ID");

Replace "YOUR-ONESIGNAL-APP-ID" with the one generated in your OneSignal dashboard.

  1. Sync your project.

Step 8: Add Internet Permission and Update Manifest

In your AndroidManifest.xml, ensure the following permissions and services are present:

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

<!-- Inside the <application> tag -->
<meta-data
    android:name="com.onesignal.app_id"
    android:value="YOUR-ONESIGNAL-APP-ID"/>

Step 9: Configure OneSignal Dashboard

  1. In your OneSignal dashboard, under Settings > Messaging, enable Push Notifications.
  2. You can also enable In-App Messages, Email, or SMS depending on your app requirements.

Step 10: Test the Notification

  1. Install your app on a device.
  2. Open the app once (OneSignal will register the user).
  3. In OneSignal, go to Audience > All Users.
  4. Click on your test user and send a test push notification.

Tips:

  • If Firebase or OneSignal requires email verification, check your inbox to complete the setup.
  • Ensure that you copy-paste keys and IDs accurately without leading/trailing spaces.
  • You can manage message formats, scheduling, and automation directly from the OneSignal dashboard.

Conclusion

Integrating OneSignal with Firebase for Android push notifications is a powerful way to enhance user engagement. Following the steps in this article, you can seamlessly set up OneSignal to work with your Firebase-backed Android app. This process not only ensures delivery of timely messages but also allows for analytics and user segmentation.

For more in-depth tutorials like this, keep referring to this blog.


Tags:

Firebase integration, OneSignal Android setup, push notifications Android, Firebase Cloud Messaging, Android app development, notification service setup

Hashtags:

#Firebase #OneSignal #AndroidDevelopment #PushNotifications #FCM #AppDevelopment #TechTutorial


Visited 52 times, 1 visit(s) today

Sahil Verma

Sahil is a mobile technology blogger and Android developer who has worked on custom ROM projects and app testing. With a background in mobile software engineering, he reviews apps, explains Android tweaks, and creates in-depth tutorials for both casual users and advanced tinkerers.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.