This is a continuation ( PART 2 ) of my previous article: ZOOM SDK Android: Learn How to Create an Online Meeting. If you know what you are doing carry on. But If you are not I suggest you read that one first. Because here I will only be explaining how to join meeting using Zoom SDK android.
As we have already made a working application to create a meeting. Here we will look at how to retrieve the ID and Password which is required to join the meeting. And finally we will join meeting with that ID and Password.
TOGGLING UI FEATURES
In our last article there was an issue after we get into the meeting. There was no way to end it because there were no icons in the video. You had to use the notification to end the meeting.
So, first let us bring back our default UI.
To do that comment out the following code block in MeetingHostHelper.kt
.
fun createInstantMeeting(): Int {
// opts.no_driving_mode = true;
// opts.no_invite = true;
// opts.no_meeting_end_message = true;
// opts.no_titlebar = true;
// opts.no_bottom_toolbar = true;
// opts.no_dial_in_via_phone = true;
// opts.no_dial_out_to_phone = true;
// opts.no_disconnect_audio = true;
// opts.no_share = true;
}
Code language: Kotlin (kotlin)
Note that I have only included the commented code.
Now we have full set of controls in our application we can continue in peace.
RETRIEVING ID & PASSWORD
Now the next step here is getting the meeting ID and Password. How can we do that ?
Let us start by changing our logic on previous article a little bit.
In MeetingHostHelper.kt
we had code which as shown below:
fun createInstantMeeting(): Int {
if (meetingService == null) return -1 // should not be null; if null return -1
val opts = InstantMeetingOptions()
opts.no_driving_mode = true;
opts.no_invite = true;
opts.no_meeting_end_message = true;
opts.no_titlebar = true;
opts.no_bottom_toolbar = true;
opts.no_dial_in_via_phone = true;
opts.no_dial_out_to_phone = true;
opts.no_disconnect_audio = true;
opts.no_share = true;
meetingService.addListener { meetingStatus, errorCode, internalErrorCode ->
if (meetingStatus == MeetingStatus.MEETING_STATUS_FAILED) {
meetingStatusListener.onMeetingFailed()
} else if (meetingStatus == MeetingStatus.MEETING_STATUS_FAILED
&& errorCode == MeetingError.MEETING_ERROR_CLIENT_INCOMPATIBLE
) {
// meeting failed because the SDK version is too low upgrade the sdk
meetingStatusListener.onMeetingFailed()
} else {
meetingStatusListener.onMeetingRunning()
}
}
return meetingService.startInstantMeeting(context, opts)
}
Code language: Kotlin (kotlin)
Now we must modify the logic in if { } else { }
block as below
fun createInstantMeeting(): Int {
if (meetingService == null) return -1 // should not be null; if null return -1
val opts = InstantMeetingOptions()
// opts.no_driving_mode = true;
// opts.no_invite = true;
// opts.no_meeting_end_message = true;
// opts.no_titlebar = true;
// opts.no_bottom_toolbar = true;
// opts.no_dial_in_via_phone = true;
// opts.no_dial_out_to_phone = true;
// opts.no_disconnect_audio = true;
// opts.no_share = true;
meetingService.addListener { meetingStatus, errorCode, _ ->
if (meetingStatus == MeetingStatus.MEETING_STATUS_INMEETING) {
meetingStatusListener.onMeetingRunning()
} else if (meetingStatus == MeetingStatus.MEETING_STATUS_FAILED) {
meetingStatusListener.onMeetingFailed()
} else if (meetingStatus == MeetingStatus.MEETING_STATUS_FAILED
&& errorCode == MeetingError.MEETING_ERROR_CLIENT_INCOMPATIBLE
) {
// meeting failed because the SDK version is too low upgrade the sdk
meetingStatusListener.onMeetingFailed()
}
}
return meetingService.startInstantMeeting(context, opts)
}
Code language: Kotlin (kotlin)
We have just modified the meetingService.addListener
block and added additional MeetingStatus.MEETING_STATUS_INMEETING
condition.
This conditional will only invoke our callback when the meeting has successfully started.
And this behavior is very important to get our id and password. We do not want it to be called multiple times with garbage value.
Next we must create a file InMeetingHelper.kt
which will be a Kotlin object
( ~ singleton in Java ). We could have done this directly in the MainActivity.kt
but let’s just keep it a little more organized.
The code in our newly created file looks something like below.
object InMeetingHelper {
fun getIdPassword(instance: ZoomSDK): Pair<String, String> {
val ims = instance.inMeetingService
val number = ims.currentMeetingNumber
val pwd = ims.meetingPassword
return Pair(number.toString(), pwd)
}
}
Code language: Kotlin (kotlin)
Save the contents and let us get back to our MainActivity.kt. Have you guessed what we need to do here ?
Exactly we will use the object
in our callback for meeting start. Let us look at the code below
override fun onMeetingRunning() {
val idPwd = InMeetingHelper.getIdPassword(ZoomSDK.getInstance())
Toast.makeText(
this@MainActivity,
"ID: ${idPwd.first} PWD: ${idPwd.second}",
Toast.LENGTH_LONG
).show()
Log.d("MainActivity", "ID: ${idPwd.first} PWD: ${idPwd.second}")
}
Code language: Kotlin (kotlin)
Now we have successfully retrieved the ID and Password from the ongoing meeting as a Pair<String, String>
.
The Pair<String, String>
contains id as .first
value and password as .second
value.
I know I should have extracted the Pair into a separate model. But I was feeling a bit lazy and you are going to port this code in your application’s flow anyway.
JOIN MEETING WITH ID & PASSWORD
Join meeting is almost same as hosting a meeting but there are quite many differences.
There are multiple way’s of joining a meeting but here we are looking at the ID and Password method.
First create a UI similar to the one shown below where we will be entering our ID and Password.
And in our MainActivity.kt
I have mapped the UI components as shown in the code below
class MainActivity : AppCompatActivity(), ZoomSDKInitializeListener, ZoomSDKAuthenticationListener {
override fun onCreate(savedInstanceState: Bundle?) {
joinMeeting = findViewById(R.id.button5)
meetingId = findViewById(R.id.editTextTextPersonName)
meetingPassword = findViewById(R.id.editTextTextPersonName2)
joinMeeting.setOnClickListener {
JoinMeetingHelper().joinMeeting(
this,
ZoomSDK.getInstance(),
meetingId.text.toString(),
meetingPassword.text.toString(),
"TechEnum"
)
}
}
}
Code language: Kotlin (kotlin)
The only interesting portion in the code is this. Where did it come from ?
JoinMeetingHelper().joinMeeting(
this,
ZoomSDK.getInstance(),
meetingId.text.toString(),
meetingPassword.text.toString(),
"TechEnum"
)
Code language: CSS (css)
Well let’s create the file JoinMeetingHelper.kt
and add the code shown below. This is where the code to join meeting resides and work’s like magic.
Let us see the code it is pretty self explanatory but I have included some comments
class JoinMeetingHelper {
/**
* This method will join the meeting with specified ID and Password
*
* @param context the usual context
* @param instance the instance of [ZoomSDK]
* @param id the id of the meeting
* @param password the password for meeting
* @param displayName the name that will be displayed to others
*/
fun joinMeeting(
context: Context,
instance: ZoomSDK,
id: String,
password: String,
displayName: String
): Int {
// if meeting service is null we cannot do anything
val meetingService: MeetingService = instance.meetingService ?: return 0
// this is required ; default options to join the meeting
val jmo = JoinMeetingOptions()
// some available options
// jmo.no_driving_mode = true;
// jmo.no_invite = true;
// jmo.no_meeting_end_message = true;
// jmo.no_titlebar = true;
// jmo.no_bottom_toolbar = true;
// jmo.no_dial_in_via_phone = true;
// jmo.no_dial_out_to_phone = true;
// jmo.no_disconnect_audio = true;
// jmo.no_share = true;
// jmo.invite_options = InviteOptions.INVITE_VIA_EMAIL + InviteOptions.INVITE_VIA_SMS;
// jmo.no_audio = true;
// jmo.no_video = true;
// jmo.meeting_views_options = MeetingViewsOptions.NO_BUTTON_SHARE;
// jmo.no_meeting_error_message = true;
// jmo.participant_id = "participant id";
// here we will define all the required parameters such as name id and pwd
val jmp = JoinMeetingParams()
jmp.displayName = displayName
jmp.meetingNo = id
jmp.password = password
// you can avoid returning anything too
return meetingService.joinMeetingWithParams(context, jmp, jmo)
}
}
Code language: Kotlin (kotlin)
The code is pretty straight forward unlike hosting a meeting.
That is all there’s to it. We have successfully completed our PART 2 of using Zoom SDK Android to join a meeting.
HAPPY CODING!
Also Read: How to get current GPS location in Android
TECHENUM
Full code can be found here on GitHub.