Rate this page:

Android: Push notifications

This article will help you to set up push notification in Android applications.

VoxImplant push notifications for Android are based on FirebaseCloud Messaging (FCM) platform and implemented as "data messages". With the help of notifications, a device can be awakened to show a new message in user’s conversation(s) and an app can be started before a call arrives.

Push notifications for calls are sent with high priority and delivered without delay.

The following tutorial explains the code needed to handle push notification and describes additional steps that should be performed to have a working Push Notifications solution for your mobile applications.

Before you start, please check that your project meets FCM requirements.

Add Firebase to the Android project

Copy URL

To add push notifications to the Android project, it is required to add Firebase to the project.

Follow the FCM instructions and recommendations to:

Tip

The Voximplant Control Panel allows you to add only one certificate of one type. If you are developing an application and need to test push notifications in both Debug and Release modes, add the same GOOGLE certificate with your application bundle + specific suffixes, for example, “.dev”, “.prod”.

See Available Roles

The Voximplant Cloud does not validate the bundle id, we use this parameter here only to identify the certificate needed to send a push notification. So, you don’t need to change the real bundle id, but only “mark” it for the Voximplant Cloud.

Do not forget to initialize the SDK correctly for Debug and Release configuration and set the suffix of the bundle id depending on the configuration.

Modify your VoxEngine scenario (for calls)

Copy URL

To let Voximplant cloud send push notifications to applications, the JavaScript scenario that initiates a call should include a push notification helper:

Add a push notification helper

Add a push notification helper

Add certificates to the Voximplant cloud

Copy URL
  1. Log in to the Firebase console with your Google account you have connected earlier in this tutorial.
  2. Go to Project Settings.
  3. Navigate to the Service Accounts tab.
  4. Navigate to Google Cloud console by clicking “Manage service accounts permissions”.
  5. Generate a key for the firebase-adminsdk account.
  6. Log in to the Voximplant control panel.
  7. Go to your application, then switch to the Push Certificates tab.
  8. Click on the Add Certificate in the upper right corner.
  9. Select GOOGLE from the Certificate for list.
  10. Upload Service account JSON file.
  11. Click on the Add button.

The Voximplant Platform supports sending push notifications to several Android applications with different package names within the same Voximplant application. If it is required to add several FCM certificates to the same Voximplant application, you have to set the application package name while adding the certificate.

Add certificate
Please note

If a package name is specified with a certificate, you must set the same package name when initializing the SDK.

See Available Roles
Initialize the SDK with a package name

Initialize the SDK with a package name

Provide a token to the Voximplant cloud

Copy URL

The Voximplant Cloud requires a device token to send a push notification. The token should be obtained from Firebase API on the application side and registered via IClient.registerForPushNotifications API:

Receive the token

Receive the token

IClient.registerForPushNotifications API may be called in any IClient state (ClientState), however, the token is registered only after the client logs in.

Register the token in these cases:

  • Token has been updated by <provider>

  • Some other Voximplant user has logged in on the device

Monitor token refresh

Copy URL

The application should also provide a token if Firebase refreshes it. Override the onNewToken method of previously extended FirebaseMessagingService and pass a new token to the Android SDK.

Handle token refresh

Handle token refresh

Handle push notifications (calls)

Copy URL

Push notifications as “data messages” are received by means of the service that overrides FirebaseMessagingService. You need to override the onMessageReceived method to get the push notification data. The onMessageReceived method is invoked in any application state (foreground or background).

We recommend the following process for handling call push notifications:

  1. Receive the push notification from Voximplant.
  2. Do connect/login if necessary.
  3. Call IClient.handlePushNotification API and provide the data that contains the “voximplant” signature.
  4. Re-register the push token.
  5. Wait for the onIncomingCall event.
  6. Show the incoming call UI to the customer.
Handle push notifications (calls)

Handle push notifications (calls)

IClient.handlePushNotification API may be called in any ClientState, but to receive an ICall instance of an incoming call, it is required to connect to the Voximplant Cloud and log in. After you do that, the IClientIncomingCallListener.onIncomingCall event is invoked to provide access to the ICall object.

Call push notifications are sent automatically. Call the callUser method in the VoxEngine scenario and push notification is automatically sent to the app. Thus, the app can wake up, connect to Voximplant, log in, and accept the call.

Tip

Use an analytics label to monitor push delivery status in real time inside Firebase console via FCM reporting dashboard.

See Available Roles

Just set the CallUserRequest.analyticsLabel property for the callUser method in your VoxEngine scenario and monitor the message delivery status.

Delivery status monitoring

Subscribe for IM push notifications for instant messaging

Copy URL

The Voximplant Cloud can send push notifications for IP messaging when one of the following events occurs:

By default, push notifications are not sent. To enable them for a user, it is required to call IMessenger.managePushNotifications API and indicate preferred MessengerNotification types. The client should log in to the Voximplant Cloud for the subscription to be successful.

Enable IM push notifications (IP messaging)

Enable IM push notifications (IP messaging)

Handle push notifications (IP messaging)

Copy URL

Push notifications as “data messages” are received by means of the service that overrides FirebaseMessagingService. You need to override the onMessageReceived method to get the push notification data.

The onMessageReceived method is invoked in any application state (foreground or background).

Once a push notification is received, use IMessengerPushNotificationProcessing to get an IMessageEvent and therefore all data and process it.

To ensure that this is a Voximplant IM push notification, check the “voximplant-im” signature in the push data.

A push notification payload contains the following information:

  • New or edited message UUID

  • Conversation UUID the message belongs to

  • Message text

  • Initiator’s user id

  • Sequential number of the event in the conversation

Handling push notifications (IP messaging)

Handling push notifications (IP messaging)

Please note that the IMessengerPushNotificationProcessing interface only converts data message to an IMessageEvent object with no modifications of it or updates of other Messenger objects instances.

Use tokens or keys for better security

Copy URL

Voximplant supports 3 ways of the authorization from SDK:

  1. With a username and a password
  2. With a username and a token
  3. With a one-time login key

Saving the password is not secure, so we would recommend that you use the "token" or "key" approach.

The token is received from an event after a successful login and can be saved and used later instead of the password.

One-time key

The "login key" approach allows you to completely avoid the use of password on the client-side by offloading it to your backend.

See Available Roles