Skip to content

Springr-Creatives/PopinAndroidSDKDemo

Repository files navigation

How to Integrate PopinAndroidSDK for Video Calls in Your Android Application

Introduction

This article explains how to integrate and use the PopinAndroidSDK library to add video calling functionality in your Android application. The SDK is easy to integrate and comes with pre-built classes like PopinConnectingDialog to handle video call connection states.

Step 1: Add PopinAndroidSDK Dependency

First, ensure that your project has the correct dependency for the PopinAndroidSDK.

  1. Open your project’s settings.gradle and add the JitPack repository to resolve the Popin library.

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            mavenCentral()
            maven { url 'https://jitpack.io' }
        }
    }
  2. Add the following dependency to your build.gradle file:

    dependencies {
        implementation 'com.github.Springr-Creatives:PopinAndroidSDK:1.5.9'
    }
  3. Update your AndroidManifest.xml with

    <meta-data
             android:name="to.popin.androidsdk.POPIN_TOKEN"
             android:value="<your_token_here>" />
    
         <activity
             android:name="to.popin.androidsdk.call.CallActivity"
             android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboardHidden"
             android:excludeFromRecents="true"
             android:exported="true"
             android:launchMode="singleTask"
             android:showWhenLocked="true"
             android:supportsPictureInPicture="true" />

Step 2: Initialize PopinAndroidSDK

Once the SDK is added, initialize the Popin service in your activity. This is typically done in the onCreate method of your main activity.

Popin.init(MainActivity.this,"test_user", "9876543210");

This method prepares the SDK to handle video calls.

Step 3: Create a Call Button

Next, you can create a button in your layout XML file (e.g., activity_main.xml) to trigger a video call:

<Button
    android:id="@+id/buttonCall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Start Call"/>

Step 4: Implement Call Button Functionality

In your MainActivity.java, locate the Button and add an OnClickListener to initiate the call:

Button buttonCall = findViewById(R.id.buttonCall);
buttonCall.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        // Show "Connecting..." dialog
        PopinConnectingDialog cdd = new PopinConnectingDialog(MainActivity.this);
        cdd.show();

        // Start the video call and handle call events
        Popin.getInstance().startCall(new PopinEventsListener() {
            @Override
            public void onCallStart() {
                // The call has started
            }

            @Override
            public void onQueuePositionChanged(int i) {
                // Update UI based on queue position (if applicable)
            }

            @Override
            public void onAllExpertsBusy() {
                // Dismiss the dialog if all experts are busy
                cdd.dismiss();
            }

            @Override
            public void onCallConnected() {
                // Dismiss the dialog when the call connects
                cdd.dismiss();
            }

            @Override
            public void onCallFailed() {
                // Dismiss the dialog if the call fails
                cdd.dismiss();
            }

            @Override
            public void onCallDisconnected() {
                // Handle call disconnection logic here
            }
        });
    }
});

Explanation of Call Events:

  • onCallStart(): Triggered when the call starts connecting.
  • onQueuePositionChanged(int i): Provides updates if the call is in a queue.
  • onAllExpertsBusy(): Called when all call participants (experts) are busy.
  • onCallConnected(): Called when the call successfully connects.
  • onCallFailed(): Called when the call fails to connect.
  • onCallDisconnected(): Called when the call disconnects.

Step 5: PopinConnectingDialog

PopinConnectingDialog is a custom dialog that appears while the call is connecting. It shows a "Please Wait" message to the user. You can customize this dialog by editing the layout or message as needed.

PopinConnectingDialog cdd = new PopinConnectingDialog(MainActivity.this);
cdd.show();

This ensures the user has visual feedback while the call is being connected.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages