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.
First, ensure that your project has the correct dependency for the PopinAndroidSDK
.
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' }
}
}
Add the following dependency to your build.gradle
file:
dependencies {
implementation 'com.github.Springr-Creatives:PopinAndroidSDK:1.5.9'
}
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);
This method prepares the SDK to handle video calls.
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"/>
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
}
});
}
});
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();