> For the complete documentation index, see [llms.txt](https://popin.gitbook.io/popin-developer-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://popin.gitbook.io/popin-developer-hub/integrating-popin-sdk-in-android.md).

# Integrating Popin SDK in Android

### On this page

* Introduction
* Step 1: Add PopinAndroidSDK Dependency
* Step 2: Initialize PopinAndroidSDK
* Step 3: Create a Call Button
* Step 4: Implement Call Button Functionality
* Step 5: PopinConnectingDialog

***

### Introduction

This guide explains how to integrate and use the **PopinAndroidSDK** to add video calling functionality to your Android application.

The SDK is easy to integrate and includes pre-built UI components such as **`PopinConnectingDialog`**, which handles call connection states and provides visual feedback to users while a call is being established.

***

### Step 1: Add PopinAndroidSDK Dependency

To begin, add the PopinAndroidSDK dependency to your project.

#### Add JitPack Repository

Open your project’s `settings.gradle` file and add the **JitPack** repository:

```gradle
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}
```

#### Add SDK Dependency

In your app-level `build.gradle` file, add the following dependency:

```gradle
dependencies {
    implementation 'com.github.Springr-Creatives:PopinAndroidSDK:1.6.8'
}
```

Sync your project to make the SDK available.

***

### Step 2: Initialize PopinAndroidSDK

Initialize the Popin SDK in your main activity. This is typically done inside the `onCreate()` method.

```java
Popin.init(MainActivity.this);
```

This prepares the SDK to manage video call sessions.

***

### Step 3: Create a Call Button

Create a button in your layout XML file (for example, `activity_main.xml`) to allow users to start a video call.

```xml
<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 attach an `OnClickListener` to initiate the video call.

```java
Button buttonCall = findViewById(R.id.buttonCall);
buttonCall.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

        // Show the "Connecting..." dialog
        PopinConnectingDialog cdd = new PopinConnectingDialog(MainActivity.this);
        cdd.show();

        // Start the video call and listen for events
        Popin.getInstance().startCall(new PopinEventsListener() {

            @Override
            public void onCallStart() {
                // Call has started connecting
            }

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

            @Override
            public void onAllExpertsBusy() {
                // No experts available
                cdd.dismiss();
            }

            @Override
            public void onCallConnected() {
                // Call successfully connected
                cdd.dismiss();
            }

            @Override
            public void onCallFailed() {
                // Call failed to connect
                cdd.dismiss();
            }

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

***

### Explanation of Call Events

| Event                           | Description                                                      |
| ------------------------------- | ---------------------------------------------------------------- |
| **onCallStart()**               | Triggered when the SDK begins connecting the call.               |
| **onQueuePositionChanged(int)** | Provides queue updates if the call is placed in a waiting queue. |
| **onAllExpertsBusy()**          | Called when no experts are available to accept the call.         |
| **onCallConnected()**           | Fired when the video call successfully connects.                 |
| **onCallFailed()**              | Called when the call cannot be established.                      |
| **onCallDisconnected()**        | Triggered when the call ends or is disconnected.                 |

***

### Step 5: PopinConnectingDialog

`PopinConnectingDialog` is a built-in dialog that appears while the video call is connecting. It typically displays a **“Please wait”** or **“Connecting…”** message to inform the user that the call is in progress.

#### Showing the Connecting Dialog

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

You can customize this dialog by modifying its layout or message to better match your application’s branding.
