Firebase Cloud Messaging

The SDK supports receiving a subset of events via FCM. The events currently supported over FCM are:

  • message:create
  • message:update

Events received directly from the server and events received via FCM will be monitored by the SDK to ensure you will only receive each event once.

Generate a Firebase Key

You will first need to generate a Firebase key to allow the server to send Firebase Messages to your application:

  • Navigate to
  • Select Create New Project.
  • Give the project a name and click Create Project.
  • Select the icon labeled Add Firebase to your Android App.
  • Enter your app's package name and click Add App.
  • This will download a file called google-services.json to your machine. We will use this file in a moment.
  • Now select Project Settings from the menu on the left by clicking the gear icon and then select the Cloud Messaging tab.
  • Copy the full Server key field. We will use this in the next step.

Add the Firebase Server Key to your VoiceLayer app

  • Log into your app's dashboard at
  • Select the My Apps tab.
  • Select Manage your App on the app you would like to configure.
  • Select Push Notifications in the menu on the left.
  • Click the Configure FCM button and enter the Server key from the previous section.

Add the google-services.json file to your app

  • Add the google-services.json file to your app by copying it into your app's app directory.
    • This will commonly be located at project-folder/app/.
    • If your project does not have an app directory look for the directory that contains the src directory.

Include the Firebase Messaging dependency

  • Add classpath '' to the dependencies section of your app's top level build.gradle file.
  • Add compile '' to the dependencies section of your app's app level build.gradle file.
  • Add apply plugin: '' at the bottom of your app's app level build.gradle file.

Implement the VoiceLayerNotificationService

First create a new class, named whatever you like, and have it extend the VoiceLayerNotificationService:

public class FirebaseMessageService extends VoiceLayerNotificationService {

    public FirebaseMessageService() {}

    // Called if a non-VoiceLayer message is received
    public void onFirebaseMessageReceived(RemoteMessage message) {}


Then register the service in your application manifest:

<service android:name=".Services.FirebaseMessageService">
        <action android:name=""/>

This service will automatically handle incoming FCM messages related to VoiceLayer. Any messages that are not associated with VoiceLayer will be passed on to your service via the onFirebaseMessageReceived method.

Register the Firebase device identifier with the server

The server needs to be told what your device's Firebase identifier is in order to target messages at your device. In order to do this you will need to retrieve the token and then send it to the server. To retrieve the token extend the FirebaseInstanceIdService and register it in your manifest:

<service android:name=".Services.FirebaseIdentifierService">
        <action android:name=""/>
public class FirebaseIdentifierService extends FirebaseInstanceIdService {

    public void onTokenRefresh() {

        // Retrieve the token
        String token = FirebaseInstanceId.getInstance().getToken();



You can cache this token however you like. You can then associate that identifier with a user via the following call once a user logs in or registers:

VoiceLayerNotificationToken serverToken = new VoiceLayerNotificationToken(token);
VoiceLayerClient.getInstance().registerNotificationToken(serverToken, null);

Note that this token is automatically disassociated with the user upon calling logout or upon registering a different token for the same user. However if you need to unregister the identifier with the user you can manually call: