Skip to content

Push Notification Setup (Android)

Backendless can deliver published messages as push notifications to Android devices. Additionally, Backendless Console can be used to publish push notifications. In order to deliver a push notification to Android, your app must be configured to use Firebase Cloud Messaging the Backendless backend must be configured with a Google API Key. Detailed instructions for setting up FCM in your app can be found at:https://firebase.google.com/docs/android/setup, however, make sure to follow the instructions below as well.

  1. Login to Firebase Console and select or create a project.
  2. Click the Add Firebase to your Android app icon and follow the on-screen instructions. Make sure to download google-services.json when prompted.
  3. Add Firebase SDK to your project per Google's instructions (step 3 in the process of adding Firebase to your Android app).
  4. Make sure the following dependencies are present in application's gradle.build file (usually app/build.gradle). Note that the version numbers will change, the numbers in the example below is the latest version at the time of this doc writing:

    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    

  5. Click the gear/settings icon located next to the Project Overview menu item and select Project Settings.
    firebase-settings

  6. Click the CLOUD MESSAGING tab:
    firebase-cloud-messaging.zoom70
  7. The Cloud Messaging tab displays project credentials. Make sure there is a Server Key generated for the project. Copy Server key: (do not use Legacy server key):
    fcm-server-key.zoom70
  8. Open Backendless Console and select your application.
  9. Click the Manage icon in the upper left corner and select the MOBILE tab.
  10. Click the ADD KEYS button in the Android Server Keys section.
    adding-android-key.zoom50
  11. Paste the Google Server key in the Secret key field. Make sure to map the key to a Backendless messaging channel. If you would like to use the key for all channels, use the All channels checkbox:
    add-google-key
  12. Click SAVE. At this point the backend is configured and is ready to publish push notifications to Android devices registered with your Backendless backend.

App/Manifest Configuration

  1. Make sure to add Backendless SDK to your app per the documentation instructions.
  2. Backendless service for Android must be registered in the app's manifest as shown below:

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

  3. Use the device registration API. For example, the following API registers the device with both FCM and Backendless. It uses the Backendless default messaging channel:

    List<String> channels = new ArrayList<String>();
    channels.add( "default" );
    Backendless.Messaging.registerDevice(channels, new AsyncCallback<DeviceRegistrationResult>() {
        @Override
        public void handleResponse(DeviceRegistrationResult response) {
            Toast.makeText( context, "Device registered!",
                    Toast.LENGTH_LONG).show();
        }
    
        @Override
        public void handleFault(BackendlessFault fault) {
            Toast.makeText( context, "Error registering " + fault.getMessage(),
                    Toast.LENGTH_LONG).show();
        }
    });
    

  4. You can verify device registration in your Backendless backend. To do open Backendless console and navigate to the Data screen. The  device will appear in the the DeviceRegistration table:
    device-in-devregistration