Android: Firebase Credentials

Directions on how to generate a Firebase Cloud Messaging API Credentials for sending Android App Notifications

πŸ“˜

For Android Apps only, not websites

This guide is for developers implementing OneSignal in an Android application for distribution on the Google Play App Store. This guide should not be used for Web Push.

A Google Service Account is a special type of account from Google that applications use to make authorized calls to a variety of APIs, including Firebase Cloud Messaging APIs. For more details, see Google's own documentation on Service Accounts. In order to send push notifications to Android devices, you will need a Service Account to generate a private key for OneSignal to utilize.

Requirements

Setup

1. Create A Firebase Project

Push Notifications require a Firebase Project. If you don't have one set up yet, click Add project and follow the directions to set up your project.

If you already have a FCM project, skip to Step 2.

Page of Projects within Firebase

Page of Projects within Firebase

2. Ensure Firebase Cloud Messaging API (V1) is Enabled

If you've just created a new project, this should already be enabled by default, and you can skip this step. However, if you are using an existing Firebase project, especially an older one, ensure Cloud Messaging API (V1) is enabled.

To check, click the gear icon next to "Project Overview" in the top left of the left-hand menu and select Project settings. Select the "Cloud Messaging" tab.

1230

Firebase gear icon submenu, showing Project Settings

If Firebase Cloud Messaging API (V1) is disabled, then click the kebab menu icon on the top right corner and open the link.

Cloud Messaging API (Legacy) does not need to be enabled as shown here. Only Firebase Cloud Messaging API (V1).

Firebase Cloud Messaging API (V1) is disabled in this image. Ensure it is enabled for your project.

On the subsequent page, click Enable. You may need to wait a few minutes for the action to propagate to Firebase systems.

<https://console.developers.google.com/apis/api/fcm.googleapis.com/overview?project=>\<PROJECT_NUMBER>

Enable Firebase Cloud Messaging API v1.

3. Generate a Private Key JSON file

In Project settings, go to the Service accounts tab.

Click Generate new private key at the bottom of the page.

Service accounts section within Firebase

Service Accounts section within Firebase

You'll then see a warning window. Click Generate key.

Generate a FCM v1 Key within Firebase

Generate a FCM v1 Key within Firebase

Save the JSON file somewhere secure. You will need to access it shortly.

πŸ“˜

Required Permissions

The following Service Account permissions are required for push notifications to work:

  • cloudmessaging.messages.create
  • firebase.projects.get

4. Configure Your OneSignal App's Android Platform Settings

In OneSignal, navigate to Settings > Platforms > Google Android > Activate

Platforms screen within OneSignal app settings

Platforms screen within OneSignal app settings

Click on Service Account JSON > Choose file and select the JSON file you downloaded from your service account.

FCM configuration screen

FCM configuration screen

🚧

What do if migrating from Legacy FCM settings

If migrating from Legacy FCM settings, you will need to select Firebase Cloud Messaging API (V1) from the dropdown menu before uploading the JSON file.

Click Save and Continue.

Select the SDK you are using for your app development and click Save & Continue.

SDK selection screen

SDK selection screen

Finally, check that you can copy your App ID and check for subscribed users before clicking Save & Continue to complete your setup.

🚧

Testing for Subscribed Users

This is only for setting up FCM for the first time. If you are updating credentials or upgrading from to FCM v1, please ignore this step (step 2).

Android configuration installation and testing screen

Android configuration installation and testing screen

πŸ‘

Done!

You now have a key to send push notifications from your app. πŸ₯³

Return to Mobile Push Quickstart

FAQ

Why do I see this error? "Cannot set the Sender ID of the platform, the App has over 100 Android users."

This error means that the file you are uploading is from a project that has a different Sender ID than what is currently used in your Android configuration. Since the push token on each of your user's devices is tied to the legacy Sender ID, updating to the new JSON file for a different Firebase project invalidates the push token. If you cannot get the JSON file for the original Firebase Project, you will need to create a new Firebase project and follow this guide to get a Service Account JSON file. You can then contact [email protected] with the OneSignal App ID/s and the attached JSON file for assistance in updating the app.

Can I change my sender ID instead of using FCM V1?

No, this is the same as uploading a JSON file for a different project. It would result in the same 1 hour wait after the user opens the app, this is why we do not allow this sender ID to change after 100 users. It is an unnecessary step and you should instead provide the JSON file here if you plan on using a different project.

Does switching from Legacy API to V1 require an update?

No this is handled entirely from the OneSignal dashboard and if you already have the Android SDK in your app, no action is needed anywhere else.

When is the actual deadline?

June 2024 per Google's announcement here. Although it is not guaranteed that we will keep the ability to use the Legacy API until this deadline, so we would advise tracking our email notifications that are being sent about these changes, and ensure you make this change as soon as you can.

Why don't I have a sender ID on OneSignal?

If you reveal your server key (Android Configuration settings for Legacy API) and it is a string that starts with 'AIz...' or it looks to only be ~40 characters long, this is a predecessor to the FCM legacy API, when it was Google Cloud Messaging. Ideally you should have created a Firebase project at some point since this change, if not you'll need to do so now. Unfortunately this is being deprecated along side the FCM Server Key and Sender ID, and you will still need to generate a JSON file for a firebase project that has a service account.

How can I check to see which apps are still using the Legacy API?

If you would like a full list of apps that you have access to, you can use the View Apps endpoint to pull a full list of apps and all of the configurations for them. If you see "gcm_key" has a value, it needs to be updated. If you see "fcm_v1_service_account_json" has a value, it is done. If you don't see either, this app is not using Android.