*

Push Notification Setup – Firebase

In this tutorial, we walk you through the steps to configure Firebase Cloud Messaging (FCM) with brainCloud.

Prerequisites

Use the FCM API key for brainCloud

Get the FCM Server Key

  • Navigate your browser to the Firebase console
  • Select your app
  • Click the Settings Icon, “Project Settings” in the top left nav bar.
  • Select “Cloud Messaging” and copy the Server Key

Save the Server Key in the brainCloud Portal

  • Navigate to the brainCloud portal and enter this key in the Notifications | Settings for Google Play.

Enable FCM For Your App

In addition to the above steps, you will need to do the following in order for FCM to work in your app.

Get the google-services.json file

This file can be found in the Firebase dashboard, and contains most the credentials you’ll need to connect your app to Firebase.

  • Navigate to the General Tab in the Firebase Project Settings
  • Download the google-services.json file
  • Add the downloaded file to your app
  • If using Unity, you can use the brainCloud example at this link. Be sure to add change the App Id and Secret to your own

Registering FCMNotification Token With brainCloud

After Authenticating a user with brainCloud, you will want to Register their FCMnotification token with brainCloud. Specifically, you’ll want to call the BrainCloudPushNotifications.RegisterDeviceToken() and pass in the registration id. In order to get this registration id, follow these steps.

Note that this example assumes you are working in Java on an Android device. For developers using Unity (or a Unity plugin such as Prime31), follow the appropriate instructions available elsewhere.

  • A starting example project can be found here: https://github.com/firebase/quickstart-android/tree/master/messaging
  • Use the FirebaseInstanceId to get the token
  • Pass that token into the brainCloud Push Notification Service
String token = FirebaseInstanceId.getInstance().getToken();
BrainCloudWrapper.getBC().getPushNotificationService().registerPushNotificationToken(Platform.GooglePlayAndroid, token, self);