Sample VoIP Calling App in Android
Tags: Kotlin, Android, Android Calling App, Messaging, Voip Calls

Sample VoIP Calling App in Android DeveloperSpace Follow Apr 12 · 5 min read

This article describes the designing & implementation of a sample VoIP calling app using CometChat Pro. CometChat Pro is Messaging & Call SDK that provides enormous features for developers to integrate chat. Using CometChat Pro UI Kit, developers can easily integrate real-time messaging & calling support in their app. By the end of this article, you will create a fully functioning Sample VoIP Calling App.

Key Components & Libraries Used

CometChat Android UI Kit — An ready to use UI Kit library which will help us to develop real-time messaging & call support in our sample app within a few minutes.

Firebase — To receive an event when the app is not in the foreground we will use Firebase Push Notification.

ConnectionService — An abstract class that will help you to build VoIP Calls in a sample app. It uses a built-in System UI to manage a call which is also called System Managed. If you wish to use your own UI to manage calls you can use Self-Managed Service.

Prerequisites

Before diving into more details please ensure that you have checked the below points.

— Android studio installed in your system.

— Android Device or Emulator to run your app.

We will begin by fetching the code from GitHub.



You can clone the project from the Sample VoIP Calling repository.

// Clone this repository git clone https://github.com/developerspace-samples/VoIP-Call-Sample.git

It’s necessary to have CometChat Account to run the app.

You can create your account in CometChat and replace the credentials with yours.

Also, please make sure to setup Push Notification Extension in CometChat.

Please click here to know How to setup Push Notification in CometChat.

Next step is to setup Firebase Account and create a new project. Once the project is created, setup an Android App in the Firebase Project and add google-services.json file in your “app” folder

Once the above mentioned configurations are done you can open the project in Android Studio. You will find the project contains two packages ‘ app’ which is our sample app and ‘ uiKit’ is a library provided by CometChat.

which is our sample app and ‘ is a library provided by CometChat. In ‘app’ you will find the ‘utils’ package under which we have files to handle Push Notification and VoIP calls.

PushNotificationService

It extends FirebaseMessageService which is used to handle Push Notification received from Firebase. We are using it to notify the message sent to a user when they are not active. We are also handling incoming & outgoing calls through it.

onMessageReceived() : This method gets triggered whenever you receive a push notification from firebase.

CometChatHelper.processMessage() : This method is provided by CometChat SDK to get BaseMessage from “data” received as JSON Object in Remote Message.

BaseMessage is base model of message in CometChat

https://docs.cometchat.io/android/v2.0/javadocs/com/cometchat/pro/models/BaseMessage.html

initiateCallService(call : Call) : This method is used to initiate a call through ConnectionService whenever a Call type message is received.

Call is a category of message used in CometChat SDK. https://docs.cometchat.io/android/v2.0/javadocs/com/cometchat/pro/core/Call.html

showMessageNotification(baseMessage: BaseMessage, title: String, alert: String) : This method is used to display and handle the notification for the message when is being received by the particular user.

Click here to get full code of PushNotificationService.kt