Search
Close this search box.

Video Conferencing Android SDK Usage

Step 1:

Create Sample Project using Android Studio.

Step: 2

Download the sdk from the below link,

http://[Your-Server-URL]/Android/Android-sdk.zip

Step: 3

Unzip the download file, you will get the ‘Android-sdk’ folder

Step: 4

Copy ‘Android-sdk’ folder and paste in this path (Your project file path +/android/app/)

Step: 5

Add ‘Android-sdk’ in your project build gradle file

allprojects {

repositories {

maven { url ” file:Android-sdk ” }

google()

jcenter()

} }

Step: 6

Add

compileOptions {

sourceCompatibility JavaVersion.VERSION_1_8

targetCompatibility JavaVersion.VERSION_1_8 }

Under build type build gradle file of app

And then add

implementation (‘org.jitsi.react:jitsi-meet-sdk:2.+’) { transitive = true }

Under dependencies in build gradle file of app

Step: 7

Code Implementation in your MainActivity java file,

Need to import the below packages,

import android.os.StrictMode;
import android.util.Log;

import org.jitsi.meet.sdk.JitsiMeet;
import org.jitsi.meet.sdk.JitsiMeetActivity;
import org.jitsi.meet.sdk.JitsiMeetConferenceOptions;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.json.JSONObject; 

Functions to implement:

  1. Get Hashkey
  2. Get Token
  3. Launch Conference  

1.  Functions to get hashkey

public static String getHashkey(URL serverdomainURL, String ConferenceName, String
ApiUserName, String NativeKey, String ApiKey){
String hashkey = null;
try {
final String HashkeyObject = “{\n” +
” \”name\”: \”” + ConferenceName + “\”,\r\n” +
” \”username\”: \”” + ApiUserName + “\”,\r\n” +
” \”Nativeappkey\”: \”” + NativeKey + “\”,\r\n”+
” \”key\”: \”” + ApiKey + “\”” + “\n}”;
URL apiUrlTogethashkey = new URL(“https://” + serverdomainURL.getHost() +”:4354/api/getHashKeyByConferenceName”);
HttpURLConnection hashkeyConnection = (HttpURLConnection)
apiUrlTogethashkey.openConnection();
hashkeyConnection.setRequestMethod(“POST”);
hashkeyConnection.setRequestProperty(“Content-Type”, “application/json”);
hashkeyConnection.setDoOutput(true);
OutputStream ops = hashkeyConnection.getOutputStream();
ops.write(HashkeyObject.getBytes());
ops.flush();
ops.close();
BufferedReader in = new BufferedReader(new
InputStreamReader(hashkeyConnection.getInputStream()));
String input;
StringBuffer result = new StringBuffer();
while ((input = in.readLine()) != null) {
result.append(input);
}
hashkey = result.toString();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(“Hashkey : “+hashkey);
return(hashkey);
}

2.  Functions to get token

public static String getToken(URL serverdomainURL, String hashkey,String ApiUserName, String
NativeKey, String ApiKey){
String token=null;
try {
final String TokenObject = “{\n” +
” \”hashkey\”: \”” + hashkey + “\”,\r\n” +
” \”username\”: \”” + ApiUserName + “\”,\r\n” +
” \”Nativeappkey\”: \”” + NativeKey + “\”,\r\n” +
” \”key\”: \”” + ApiKey + “\”,\r\n” +
” \”IsMobile\”: \”true\”” + “\n}”;
System.out.println(TokenObject);
URL apiURLtogetToken = new URL(“https://” + serverdomainURL.getHost() +
“:4354/api/getConferenceNameByHashKey”);
HttpURLConnection postConnection = (HttpURLConnection)
apiURLtogetToken.openConnection();
postConnection.setRequestMethod(“POST”);
postConnection.setRequestProperty(“Content-Type”, “application/json”);
postConnection.setDoOutput(true);
OutputStream os = postConnection.getOutputStream();
os.write(TokenObject.getBytes());
os.flush();
os.close();
BufferedReader inn = new BufferedReader(new
InputStreamReader(postConnection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = inn.readLine()) != null) {
response.append(inputLine);
}
inn.close();
JSONObject tokendetail = new JSONObject(response.toString());
token = tokendetail.get(“token”).toString();
}
catch (Exception e){
e.printStackTrace();
}
System.out.println(“Token : “+token);
return token;
}

3.  Functions to get launch conference:

private void launchvideoconference(URL serverdomainURL, String ConferenceName, String Token,
String HashKey) {
try {
JitsiMeetConferenceOptions defaultOptions
= new JitsiMeetConferenceOptions.Builder()
.setFeatureFlag(“chatOption.enabled”, true) // for chat enable
.setSubject(ConferenceName) // for display name
.setVideoMuted(false) // for video mute
.setAudioMuted(true) // for audio mute
.setServerURL(serverdomainURL)
.setWelcomePageEnabled(true)
.setToken(Token)
.build();
JitsiMeet.setDefaultConferenceOptions(defaultOptions);
JitsiMeetConferenceOptions options
= new JitsiMeetConferenceOptions.Builder()
.setRoom(HashKey)
.build();
// Launch the new activity with the given options. The launch() method takes care
// of creating the required Intent and passing the options.
JitsiMeetActivity.launch(this, options); // this is context
}
catch (Exception e){
e.printStackTrace();
}
}

 

Call above 3 functions (hashkey, token, launch conference) using below conference function:

private void Conference(String YourDomainName, String ConferenceName, String ApiUserName,
String ApiKey,String NativeKey){
URL serverdomainURL=null;
String HashKey;
String Token;
StrictMode.ThreadPolicy threadPolicy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(threadPolicy);
try {
serverdomainURL = new URL(YourDomainName+”/conference/”);
} catch (Exception e) {
e.printStackTrace();
}
HashKey=getHashkey(serverdomainURL,ConferenceName,ApiUserName,NativeKey,ApiKey);//to get hashkey for conference
Token=getToken(serverdomainURL,HashKey,ApiUserName,NativeKey,ApiKey); //to get token for conference
launchvideoconference(serverdomainURL,ConferenceName,Token,HashKey); //launch conference
}

Initialize variables need for connect conferences are given below:

String YourDomainName = “https://yourdomainname.com”; //eg: https://domain.com
String ConferenceName = “##########”;
String ApiUserName = “########”;
String ApiKey = “##########”;
String NativeKey=””; //No need to provide native key for Testing mode. Native key needed only for Production mode

Call Conference function inside onCreate function:

conference(YourDomainName,ConferenceName,ApiUserName,ApiKey,NativeKey);

For launch conference with chat only option enable:

JitsiMeetConferenceOptions defaultOptions
= new JitsiMeetConferenceOptions.Builder()
.setFeatureFlag(“chatOption.enabled”,true) // for chat open
.setSubject(conferencename) // for display name
.setVideoMuted(true) // for video mute
.setAudioMuted(true) // for audio mute
.setServerURL(serverdomainURL)
.setWelcomePageEnabled(false)
.build();

For launch conference with Video only option enable:

JitsiMeetConferenceOptions defaultOptions
= new JitsiMeetConferenceOptions.Builder()
.setFeatureFlag(“chatOption.enabled”,false)
.setSubject(conferencename) // for display name
.setAudioMuted(true) // for audio mute
.setServerURL(serverdomainURL)
.setWelcomePageEnabled(false)
.build();

For launch conference with Audio only option enable:

JitsiMeetConferenceOptions defaultOptions
= new JitsiMeetConferenceOptions.Builder()
.setFeatureFlag(“chatOption.enabled”,false)
.setSubject(conferencename) // for display name
.setVideoMuted(true) // for video mute
.setServerURL(serverdomainURL)
.setWelcomePageEnabled(false)
.build();

Step 8:

Run Project using Android studsio

  • Clean Project(BuildàClean Project)
  • Build Project(BuildàBuild/Rebuild Project)
  • Run app using emulator