Rate this page:

Android SDK

VoxImplant push notifications for Android are based on FirebaseCloud Messaging (FCM) platform and implemented as the "data messages". Using notifications, a device can be awakened and an app started before a call arrives. Our SDK requires Android API 16 (4.1), while push notifications support also requires Play Services 10.0.1 or higher to be available on the device. Our Android SDK contains a sample application with all the code needed to handle push notification. Following tutorial explains that code and describes additional steps that should be performed to have a working Push Notifications solution for your mobile applications. Push notifications are available since Android SDK version 2.1.0

Add Firebase to the Android project

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

  • Open project in the Android Studio
  • Select Tools, then Firebase from the top menu. Assistant window will open
  • Expand the Cloud Messaging item and click on the Set up Firebase Cloud Messaging
  • Click the Connect to Firebase button. Browser windows will open where you will be asked to login into the Firebase with your Google account. After logging in, the "Connect to Firebase" window will be displayed in the Android Studio.
  • Follow the wizard to add Firebase support into the project
  • Click the Add FCM to your app button and then click on the Accept Changes button to modify your project.

Provide token to the Voximplant cloud

After each successful login into the Voximplant cloud application should get a push notification token from Firebase and pass it to the Android SDK:

Receiving the token

Receiving the token

Handle push notifications

  • Implement Android Service that extends FirebaseMessagingService. Add the service to the Android application manifest to ensure the service's auto-launch on application start.
  • Override the onMessageReceived method of that service
  • Inside the onMessageReceived method call, get a message payload via getData and check, that it contains the "voximplant" signature
Handling push notifications

Handling push notifications

  • After the message with "voximplant" signature is received, if the application is not connected or logged in to the Voximplant cloud, the application should login (and reconnect, if needed) in order to handle an incoming call. It is strongly recommended to disable connectivity check when using Voximplant connect while handling push notifications since it increases the connect time and application may not meet the time requirements to react on push notification.

Monitor token generation

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 in that method.

Add certificates to the Voximplant cloud

  1. Login into the Firebase console with your Google account you have connected early in this tutorial
  2. In the Recent Projects section click on the project that was previously added to Firebase during this tutorial
  3. Click on the Android application name and select Settings
  4. Select the Cloud Messaging tab from the top navigation bar
  5. Copy Sender ID and Server key strings
  6. Login into 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. In the Certificate for list select the GOOGLE
  10. Enter the Sender ID and Server key strings copied from the Firebase
  11. Click on the Add button

Modify VoxEngine scenario

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

Adding a push notification helper

Adding a push notification helper

This code will make VoxEngine manage timeouts automatically so they won't be configurable. VoxEngine will wait for the user login event for 20 seconds after a push notification was sent. If the user didn't logged in during this time, the call will be failed. If the user logged in, he will receive the incoming call event and have the same time to answer a call as for general call.

Push notifications are sent automatically

Just use the callUser method from the VoxEngine scenario and push notification will be automatically sent to the app so the app can wake up, connect to Voximplant, login and accept the call.

Use tokens or keys for better security

Voximplant support 3 ways to login from the SDK: with a username and a password, with a username and a token or with a one-time login key. Saving the password is not secure, so we would recommend to use "token" or "key" approach. The token is received from an event after the successful login, can be saved and used later instead of a password. The "login key" approach allows to completely exclude password usage on client-side by offloading it to your backend. Please refer to this article for details.