ZEGOCLOUD: Major product ZEGO Call Gets Released! Come and use the ZEGOCall SDK to quickly build your voice/video call app
Tags: mobile, api, tutorial, firebase
Published: 2022-05-16 11:23:40


![avatar](https://resource.zegocloud.com/content_resource/2022/05/16/16519207976762.png)

## Introduction
In the wake of the COVID-19 pandemic, more and more offline call scenarios are being moved and implemented online, such as online learning, online doctor consultation, online conferences, online dating, and other scenarios. So, you may wonder how many developers and what technical capabilities you need if you want to integrate voice and video calls into your app. And I guess you'll find your answer after finishing reading this.

This article shows how to use ZEGOCLOUD's ZEGOCall SDK to quickly integrate the voice/video call feature into your app or build a voice/video call app without any development experience and involving developers.

## Features
### What can ZEGOCall SDK provide 

The ZEGOCall SDK provides plenty of features, such as Google login, an online user list, voice and video calls, offline notifications, and more. And the open-source sample code and the technical documentation for those features are fully available for you. 

![calluikit_960_10fps](https://resource.zegocloud.com/content_resource/2022/05/16/calluikit96010fps.gif)
The following table shows ZEGOCall SDK's features: 

| Feature | Description |
|-------|--------|
| Voice and Video call | Support making one-to-one or group outbound voice and video calls. |
| Call invitation | Support making outbound calls to online and offline users. |
| Device configuration | Support enabling and disabling the microphone and camera, and switching between the front-facing camera and rear camera. |
| Video configuration | Support configuring the video resolution, frame rate, bitrate, and more.|
| Audio configuration | Support configuring sound quality, sound effects, and more.|
| View configuration | Support configuring the view to be displayed during a call as needed. |
| Real-time quality analysis |<ul><li> Before a voice or video call, automatically conduct the microphone, camera, and speaker tests.</li><li>During a call, the call quality data, and network data is updated in real time.</li><li>After the call ends, ZEGOCLOUD provides you with the quality analysis platform Prism and a quality report for you to review and check the call quality.</li></ul> |


### When do you need the ZEGOCall SDK
1. For a green-hand developer: when trying to start a new project
2. For an enterprise: when trying to build a voice/video chat app
3. When trying to add a voice/video call feature into an existing app


To meet different needs, ZEGOCLOUD's ZEGOCall SDK uses a layered architecture. Details are as shown in the figure below:

![meet](https://resource.zegocloud.com/content_resource/2022/05/16/16507993587607.png)

The demo app of ZEGO Call has already integrated the features required by a video call application, you can compile it directly into an app and make it goes live. 
And we also provide two different SDKs for you: the `CallUIKit` and the `Call SDK`.
Choose to integrate the `CallUIKit`: If you want to customize the business logic and maintain the user list on your own. And voice/video call interactions and UI are implemented by the `CallUIKit`.
Choose to integrate the `Call SDK`: If you want to customize the UI on your own. The transmission of underlying data, voice/video call connection, and others are implemented by the `Call SDK`.


## How to integrate the ZEGOCall SDK
### Step 1. Create a ZEGOCLOUD account
- Create an account in [ZEGOCLOUD Official](https://www.zegocloud.com/account/signup?_source=medium&article=6). 

![create an account](https://resource.zegocloud.com/content_resource/2022/05/16/16508858112630.gif)

### Step 2. Create a new project
- Create a project in [ZEGOCLOUD Admin Console](https://console.zegocloud.com?_source=medium&article=6). 

![creata a project](https://resource.zegocloud.com/content_resource/2022/05/16/16508858234388.gif)

### Step 3. Create a Firebase project
Create a Firebase project in the [Firebase console](https://console.firebase.google.com/). For more details, see [Firebase Documentation](https://firebase.google.com/docs/functions/get-started).

![create firebase](https://resource.zegocloud.com/content_resource/2022/05/16/16508878183242.gif)

### Step 4. Deploy the Firebase Cloud Functions

ZEGO Call uses the Firebase Cloud Functions as the business server by default, we recommend you activate and deploy it before integrating the ZEGOCall SDK.

1.Create a new Realtime Database in Firebase. 
![create firebase](https://resource.zegocloud.com/content_resource/2022/05/16/16509539597267.gif)

2.Edit the rules of the Realtime Database by adding the following:
```json
{
  "rules": {
        ".read": "auth.uid != null",
        ".write": "auth.uid != null",
  }
}
```
![rules](https://resource.zegocloud.com/content_resource/2022/05/16/16509540888361.jpg)

3.Install the CLI via npm.
    ```
    npm install -g firebase-tools
    ```
    ![Install the CLI](https://resource.zegocloud.com/content_resource/2022/05/16/16509597070259.gif)

4.Run the `firebase login` to log in via the browser and authenticate the firebase tool.   
![firebase login](https://resource.zegocloud.com/content_resource/2022/05/16/16509597756605.gif)
5.Run `firebase init functions`. The tool gives you an option to install dependencies with npm. It is safe to decline if you want to manage dependencies in another way, though if you do decline you'll need to run npm install before emulating or deploying your functions.
![init functions](https://resource.zegocloud.com/content_resource/2022/05/16/16509598453979.gif)
6.Download the [Cloud function sample code](https://github.com/ZEGOCLOUD/call_firebase_funcitons). 
![Download file](https://resource.zegocloud.com/content_resource/2022/05/16/16509598698059.gif)
7.Copy the `firebase.json`, `functions\index.js` files and `functions\token04` folder in the sample code to your cloud function project, overwrite files with the same name.  

![token](https://resource.zegocloud.com/content_resource/2022/05/16/16509602283059.jpg)
![copy file](https://resource.zegocloud.com/content_resource/2022/05/16/16509599977538.gif)

8.Modify the `index.js` file, fill in the AppID and ServerSecret you get from [ZEGOCLOUD Admin Console](https://console.zegocloud.com?_source=medium&article=6) correctly.
![write appID](https://resource.zegocloud.com/content_resource/2022/05/16/16509600852118.gif)

9.In Firebase CLI, run the `firebase deploy --only functions` command to deploy the cloud functions. 
![firebase](https://resource.zegocloud.com/content_resource/2022/05/16/16509614647425.jpg)

### Step 5. Copy file into the project
To integrate the ZEGOCallUIKit, do the following:
1.Download the [Sample codes](https://github.com/ZEGOCLOUD/call_android), import the `zegocall` and `zegocalluikit` modules to your project root directory (Create a new project if you don't have an existing project).

2.Add the following code to the `settings.gradle` file:
    
    ```gradle
    include ':zegocall'
    include ':zegocalluikit'
    ```

3.Modify the `build.gradle` file of your application (in the **app** folder), add the following code: 

    ```groovy
    ...
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'com.google.firebase.crashlytics'

    android {
        ...
    }

    dependencies {
        ...

        // Google Sign In SDK (only required for Google Sign In)
        implementation 'com.google.android.gms:play-services-auth:20.1.0'
        implementation project(path: ':zegocalluikit')
    }
    ```
    ![google1](https://resource.zegocloud.com/content_resource/2022/05/16/16509619605886.png)
    ![google2](https://resource.zegocloud.com/content_resource/2022/05/16/16509619707212.png)
    
4.Modify the `build.gradle` file of your project, add the following code: 

    <div class="mk-hint">

    If your Android Studio version is higher than "bumblebee 2021.1.1 patch 1", please modify the maven configuration in the `setting.gradle`.
    
    </div>

    ```groovy
    buildscript {
        repositories {
            maven { url 'https://www.jitpack.io' }
            ...
        }
        dependencies {
            ...
            classpath 'com.google.gms:google-services:4.3.10'
            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
        }
    }
    ```
    ![dependencies](https://resource.zegocloud.com/content_resource/2022/05/16/16509619992007.png)

5.Add Firebase to your project by referring to the [Add Firebase to your Android project: Step 2-3](https://firebase.google.com/docs/android/setup), and make sure you have downloaded and added the `google-services.json` file to your app directory.

6.Click **Sync now**.

### Step 6. Initialize the ZEGOCallUIKit
To initialize the ZEGOCallUIKit, get the `ZegoCallManager` instance, pass the AppID of your project. 

```java
// Initialize the ZEGOCallUIKit. We recommend you call this method when the application starts.
// appID is the AppID you get from ZEGOCLOUD Admin Console. 
// The last parameter refers to the Application object of the this project.
ZegoCallManager.getInstance().init(appID, this, new ZegoTokenProvider() {
    @Override
    public void getToken(String userID, ZegoTokenCallback callback) {
     //imply with your own methed to get zego RTC token
     // String rtcToken = "";
    //  callback.onTokenCallback(errorCode, rtcToken);
        }
    });
```

### Step 7. Get a Token
After deploying the Firebase Cloud Functions, here we get a Token by calling the client API methods of Firebase Cloud Functions:

```java
private void getTokenFromCloudFunction(String userID, long effectiveTime) {
    Map<String, Object> data = new HashMap<>();
    data.put("id", userID);
    data.put("effective_time", effectiveTime);

    FirebaseFunctions.getInstance().getHttpsCallable("getToken")
        .call(data)
        .continueWith(new Continuation<HttpsCallableResult, Object>() {
            @Override
            public Object then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                return task.getResult().getData();
            }
        })
        .addOnCompleteListener(new OnCompleteListener<Object>() {
            @Override
            public void onComplete(@NonNull Task<Object> task) {
                if (!task.isSuccessful()) {
                    Exception e = task.getException();
                    if (e instanceof FirebaseFunctionsException) {
                        FirebaseFunctionsException ffe = (FirebaseFunctionsException) e;
                        FirebaseFunctionsException.Code code = ffe.getCode();
                        Object details = ffe.getDetails();
                    }
                    return;
                }
                HashMap<String, String> result = (HashMap<String, String>) task.getResult();
                String token = result.get("token");
            }
        });
}
```

### Step 8. User login

ZEGO Call does not provide user management capabilities yet. You will need to have users log in to Firebase and then call the `setLocalUser` method to set user information to CallUIKit based on the login result.

Firebase provides multiple login authentication modes. The following uses Google login as an example.
For more modes, refer to the [Firebase official](https://firebase.google.com/docs/auth/where-to-start).

```java
// init google sign in 
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestIdToken(CLIENT_ID)
        .requestEmail()
        .build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

// when button is clicked,invoke this
private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

// overwrite onActivityResult to get google sign in result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        try {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = task.getResult(ApiException.class);
            AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
            FirebaseAuth.getInstance().signInWithCredential(credential)
                .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        // Sign in success, update UI with the signed-in user's information
                        Log.d(TAG, "signInWithCredential:success");
                        FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
                        ZegoCallManager.getInstance().setLocalUser(currentUser.getUid(), currentUser.getDisplayName());
                    } else {
                        // If sign in fails, display a message to the user.
                        Log.w(TAG, "signInWithCredential:failure", task.getException()); 
                    }
                }
            });
        } catch (ApiException e) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e);
        }
    }
}

```

### Step 9. Make outbound calls

To make an outbound voice call, call the `callUser` method and set the `zegoCallType` parameter to `ZegoCallType.Voice`.

<div class="mk-hint">

For Android 6.0 or later, some important permissions must be requested both at runtime and declared statically in the file `AndroidMainfest.xml`, you can add the following code to do so (requestPermissions is a method of an Android Activity).
For more information, refer to the [Request app permissions](https://developer.android.com/training/permissions/requesting).

</div>


```java
// shows how to request camera and audio permission at run time
String[] permissionNeeded = {
        "android.permission.CAMERA",
        "android.permission.RECORD_AUDIO"};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    if (ContextCompat.checkSelfPermission(this, "android.permission.CAMERA") != PackageManager.PERMISSION_GRANTED ||
        ContextCompat.checkSelfPermission(this, "android.permission.RECORD_AUDIO") != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(permissionNeeded, 101);
    }
}
```
You can make a call after getting the access permission of the camera and microphone.

```java
// userInfo refers to the user info(ID and name) of the user you want call. 
// ZegoCallType.Voice indicates that you make a voice call.
ZegoCallManager.getInstance().callUser(userInfo, ZegoCallType.Voice);
```

To make an outbound video call, call the `callUser` method and set the `zegoCallType` parameter to `ZegoCallType.Video`.


```java
// userInfo refers to the user info(ID and name) of the user you want call. 
// ZegoCallType.Video indicates that you make a video call.
ZegoCallManager.getInstance().callUser(userInfo, ZegoCallType.Video);
```

After making a call, the CallUIKit shows the UI of the current state automatically for both the callee and caller (integrated the CallUIKit is required), and, you can operate on the UI for further operations.

The following displays when the caller calls the method to make a call (make a voice call for illustration)
![call](https://resource.zegocloud.com/content_resource/2022/05/16/16509616743277.png)

### Step 10. Listen for the incoming calls

To receive in-time notifications when receiving incoming calls, call the `startListen` method to listen for the call invitations. The corresponding UI displays and you can operate on the UI for further calling responses.



```java
// Listen for the call invitations.
// Pass the current Activity.
ZegoCallManager.getInstance().startListen(this);
```

When the app is running in the frontend: the following black pop-up prompts automatically when the callee receives an incoming call (make a voice call for illustration)
![running](https://resource.zegocloud.com/content_resource/2022/05/16/16509616869776.png)


When the app is running in the backend: the following black pop-up prompts after granting the offline notification permission when the callee receives an incoming call. For more, refer to the document [canDrawOverlays](https://developer.android.com/reference/android/provider/Settings#canDrawOverlays(android.content.Context)).
Different phone vendors may require different settings based on the operating system and version, for example, [OPPO](https://support.oppo.com/en/answer/?aid=neu10359), [Vivo](https://www.vivoglobal.ph/questionlist/How-to-enable-or-disable-Floating-window-of-my-apps/).


### Step 11. Stop listening for the incoming calls


To stop listening for the incoming calls, call the `stopListen` method. You won't receive notifications after calling this method.

```java
// Stop listening for the incoming calls.
// Pass the same Activity that you used to start listening for the incoming calls.
ZegoCallManager.getInstance().stopListen(this);
```
### Step 12. Offline notifications

The Firebase Cloud Functions has implemented the offline notifications of the firebase cloud message, and it sends a data type fcm message when making outbound calls. For clients to receive offline notifications,  integrate the [firebase cloud message](https://firebase.google.com/docs/cloud-messaging/android/client), and start the app when receiving the offline notifications:

```java
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    Map<String, String> data = remoteMessage.getData();

    boolean isAppNotStart = !AppUtils.isAppForeground() && ActivityUtils.getActivityList().isEmpty();
    boolean isDeviceRestart = AppUtils.isAppForeground() && ActivityUtils.getActivityList().isEmpty();
    if (isAppNotStart || isDeviceRestart) {
        if (data.size() > 0) {
            AppUtils.relaunchApp();
        }
    }
}
```

### Step 13. Upload logs

When you encounter problems when using your app, call the `uploadLog`  method to upload logs for us to locate and help you faster.


```java
ZegoCallManager.getInstance().uploadLog(errorCode -> {
    // Callback for the result of upload SDK logs. 
});
```

### Step 14. Deinitialize the ZEGOCallUIKit

After finishing using the ZEGO Call, call the `unInit` method to deinitialize the SDK.

```java
ZegoCallManager.getInstance().unInit();
```

## References

1. To know more about ZEGO Call, see [ZEGOCLOUD's ZEGOCall SDK](https://docs.zegocloud.com/article/13840.html?_source=devm&article=6).
2. To download the ZEGOCall SDK, go to [ZEGOCLOUD's ZEGOCall SDK](https://github.com/ZEGOCLOUD/call_android).
3. To learn more about what you can build with the real-time audio and video communication capabilities we provide, visit [ZEGOCLOUD official website](https://zegocloud.com?_source=dev&article=6).