Call Kit
  • iOS
  • Android : Java
  • Web
  • Flutter
  • React Native
  • Overview
  • Quick start
    • Quick start
    • Quick start (with call invitation)
  • Customize the call
    • Overview
    • Set avatar for users
    • Add custom components to the call
    • Configure layouts
    • Hide the label on the user view
    • Implement an audio-only call
    • Customize the menu bar
    • Set a hangup confirmation dialog
    • Call invitation config
    • Calculate call duration
  • Enhance the call
    • Screen sharing
    • Minimize video call window
    • Advanced beauty effects
    • Use Tokens for authentication
  • Troubleshooting call invitations
  • FAQ
  • API Reference
    • API
    • Event
    • Config
  • Migration guide
  • Documentation
  • Call Kit
  • Quick start
  • Quick start (with call invitation)

Quick start (with call invitation)

Last updated:2024-03-26 17:04

You can refer to this document to understand the effects of the offline call invitation (system-calling UI) and complete the basic integration.

  1. If your project needs Firebase integration or customization of features like ringtone and UI, complete the basic integration first and then refer to Customize the call and Enhance the call for further configuration.

  2. Offline call invitation configuration is complex. If you only require online call invitations, please skip the steps related to firebase console.

UI Implementation Effects

Recorded on Xiaomi , the outcome may differ on different devices.

Online call online call (Android App background) offline call (Android App killed)

Integrate the SDK with the call invitation feature

Add ZegoUIKitPrebuiltCall as dependencies

  1. Add the jitpack configuration.
  • If your Android Gradle Plugin is 7.1.0 or later: enter your project's root directory, open the settings.gradle file to add the jitpack to dependencyResolutionManagement > repositories like this:
dependencyResolutionManagement {
   repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
   repositories {
      google()
      mavenCentral()
      maven { url 'https://storage.zego.im/maven' }   // <- Add this line.
      maven { url 'https://www.jitpack.io' } // <- Add this line.
   }
}

If you can't find the above fields in settings.gradle, it's probably because your Android Gradle Plugin version is lower than v7.1.0.

For more details, see Android Gradle Plugin Release Note v7.1.0.

  • If your Android Gradle Plugin is earlier than 7.1.0: enter your project's root directory, open the build.gradle file to add the jitpack to allprojects->repositories like this:
allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://storage.zego.im/maven' }   // <- Add this line.
        maven { url "https://jitpack.io" }  // <- Add this line.
    }
}
  1. Modify your app-level build.gradle file:
    dependencies {
     ...
     implementation 'com.github.ZEGOCLOUD:zego_uikit_prebuilt_call_android:+'    // Add this line to your module-level build.gradle file's dependencies, usually named [app].
    }
  1. notification : if your targetSdk in project is 33 or after, please dynamic request notification permissions.Without this permission,we can't send notifications.Please refer to Notification runtime permission for more details.

  2. Appear on top / Display pop-up window: we need 'Appear on top ' or 'Display pop-up window' permission on some phones such as 'Xiaomi',without this permission,we can't show offline invitation calls.You can request this permission as follows:

     // need a activityContext.
    PermissionX.init(activityContext).permissions(permission.SYSTEM_ALERT_WINDOW)
       .onExplainRequestReason(new ExplainReasonCallback() {
           @Override
           public void onExplainReason(@NonNull ExplainScope scope, @NonNull List<String> deniedList) {
               String message = "We need your consent for the following permissions in order to use the offline call function properly";
               scope.showRequestReasonDialog(deniedList, message, "Allow", "Deny");
           }
       }).request(new RequestCallback() {
           @Override
           public void onResult(boolean allGranted, @NonNull List<String> grantedList,
               @NonNull List<String> deniedList) {
           }
       });
  3. Autostart: Some devices require special permissions to be enabled in order for your app to automatically display in the foreground when receiving a offline push message (such as Xiaomi). Therefore, you need to guide your app users to enable autostart permissions to make the feature work.

Initialize the call invitation service

Call the init method After the user logs in, and specify the userID and userName for connecting the Call Kit service.

We recommend calling this method immediately after the user logs into your app.

  1. After the user logs in, it is necessary to Initialize the ZegoUIKitPrebuiltCallService to receive call invitations.
  2. When the user logs out,it is nessary to uninit to clear the previous login records,preventing any impact on the next login
Application application = ; // Android's application context
long appID = ;   // yourAppID
String appSign =;  // yourAppSign
String userID =; // yourUserID, userID should only contain numbers, English characters, and '_'. 
String userName =;   // yourUserName

ZegoUIKitPrebuiltCallInvitationConfig callInvitationConfig = new ZegoUIKitPrebuiltCallInvitationConfig();

ZegoUIKitPrebuiltCallService.init(getApplication(), appID, appSign, userID, userName,callInvitationConfig);

Props of ZegoUIKitPrebuiltCallService component

Property  Type  Required Description
appID
String 
Yes
The App ID you get from ZEGOCLOUD Admin Console
appSign
String 
Yes
The App Sign you get from ZEGOCLOUD Admin Console
userID
String 
Yes
userID can be something like a phone number or the user ID on your own user system. userID can only contain numbers, letters, and underlines (_).  
userName 
String
Yes
userName can be any character or the user name on your own user system.

Add the button for making call invitations

You can customize the position of the ZegoSendCallInvitationButton accordingly, pass in the ID of the user you want to call.

String targetUserID = ; // The ID of the user you want to call.
String targetUserName = ; // The username of the user you want to call.
Context context = ; // Android context.

ZegoSendCallInvitationButton button = new ZegoSendCallInvitationButton(context);
button.setIsVideoCall(true);
button.setResourceID("zego_uikit_call"); // Please fill in the resource ID name that has been configured in the ZEGOCLOUD's console here.
button.setInvitees(Collections.singletonList(new ZegoUIKitUser(targetUserID,targetUserName)));

Props of ZegoSendCallInvitationButton

Property   Type Required Description
invitees
Array
Yes
The information of the callee. userID and userName are required. For example: [{ userID: inviteeID, userName: inviteeName }]
isVideoCall 
Boolean
Yes
If true, a video call is made when the button is pressed. Otherwise, a voice call is made.
resourceID 
Boolean
No
resourceID can be used to specify the ringtone of an offline call invitation, which must be set to the same value as the Push Resource ID in ZEGOCLOUD Admin Console.
timeout 
Number
No
The timeout duration. It's 60 seconds by default.

For more parameters, go to Custom prebuilt UI.

Now, you can make call invitations by simply clicking on this button.

Complete sample code

github demo

Configure Offline invitaion(FCM)

1. Firebase Console and ZEGO Console Configuration

  • step1. In the Firebase console: Create a project. (Resource may help: Firebase Console)
  • step2. In the ZegoCloud console: Add FCM certificate, create a resource ID;

​In the create resource ID popup dialog, you should switch to the VoIP option for APNs, and switch to Data messages for FCM.

When you have completed the configuration, you will obtain the resourceID. You can refer to the image below for comparison.

After the above is completed, the resourceID property value of ZegoSendCallInvitationButton needs to be replaced with the resource ID you get.

  • step3. In the Firebase console: Create an Android application and modify your code;

2. Check whether the local config is set up properly.

python3 zego_check_android_offline_notification.py
  • You will see the following if everything goes well:
✅ The google-service.json is in the right location.
✅ The package name matches google-service.json.
✅ The project level gradle file is ready.
✅ The plugin config in the app-level gradle file is correct.
✅ Firebase dependencies config in the app-level gradle file is correct.

3. Debugging using the sample code.

Considering the complicated steps of configuring the offline call invitation, we recommend you download the Sample code for debugging during your integration.

About Firebaes Cloud Messaging

If your project has already integrated Firebase Cloud Messaging, you will need additional steps to complete the integration. Please refer to the FAQ for compatibility issues with Firebase.

Run & Test

Now you have finished all the steps!

You can simply click the Run on Android Studio to run and test your App on your device.

Resources

Page Directory