Skip to main content
Version: 0.1.x

Precall Setup - Android

Picture this: before diving into the depths of a video call, imagine giving your setup a quick check-up, like a tech-savvy doctor ensuring all systems are a go. That's essentially what a precall experience does- it’s like your extensive debug session before the main code execution—a crucial step in ensuring your app's performance is top-notch.

Why is it necessary?

Why invest time and effort into crafting a precall experience, you wonder? Well, picture this scenario: your users eagerly join a video call, only to encounter a myriad of technical difficulties—muted microphones, pixelated cameras, and laggy connections. Not exactly the smooth user experience you had in mind, right?

By integrating a robust precall process into your app, developers become the unsung heroes, preemptively addressing potential pitfalls and ensuring that users step into their video calls with confidence.

Step-by-Step Guide: Integrating Precall Feature

Step 1: Check and Request Permissions

  • Begin by ensuring that your application has the necessary permissions to access user devices, such as the camera, microphone and Bluetooth.
  • Utilize the checkPermissions() method of the VideoSDK class to verify if permissions are granted.
  • If the permissions are not granted, the method will request the required permissions.
  • PermissionHandler is used to manage and handle permission-related events (such as granting, denying, or blocking permissions).
    • onGranted(): This method is called when all requested permissions are granted.
    • onBlocked(): This method is called when one or more permissions are permanently blocked (i.e., the user has checked "Don't ask again").
    • onDenied(): This method is called when one or more permissions are denied.
    • onJustBlocked(): This method is called when one or more permissions are just blocked (i.e., the user has just checked "Don't ask again" for the first time).
private fun checkPermissions() {
val permissionList: MutableList<Permission> = ArrayList()
permissionList.add(Permission.audio)
permissionList.add(Permission.video)
permissionList.add(Permission.bluetooth)
val options = Permissions.Options()
.setRationaleDialogTitle("Info")
.setSettingsDialogTitle("Warning")
VideoSDK.checkPermissions(this,
permissionList,
options,
permissionHandler
)
}

private val permissionHandler: PermissionHandler = object : PermissionHandler() {
override fun onGranted() {
Log.d("VideoSDK Permission", "onGranted: All permissions granted")
}
override fun onBlocked(
context: Context,
blockedList: java.util.ArrayList<Permission>
): Boolean {
for (blockedPermission in blockedList) {
Log.d("VideoSDK Permission", "onBlocked: $blockedPermission")
}
return super.onBlocked(context, blockedList)
}

override fun onDenied(
context: Context,
deniedPermissions: java.util.ArrayList<Permission>
) {
for (deniedPermission in deniedPermissions) {
Log.d("VideoSDK Permission", "onDenied: $deniedPermission")
}
super.onDenied(context, deniedPermissions)
}

override fun onJustBlocked(
context: Context,
justBlockedList: java.util.ArrayList<Permission>,
deniedPermissions: java.util.ArrayList<Permission>
) {
for (justBlockedPermission in justBlockedList) {
Log.d("VideoSDK Permission", "onJustBlocked: $justBlockedPermission")
}
super.onJustBlocked(context, justBlockedList, deniedPermissions)
}
}

Step 2: Render Device Lists

  • You can fetch and render lists of available video and audio devices using the getVideoDevices() and getAudioDevices() methods of the VideoSDK class, respectively.
private fun getAudioaDevices() {

val audioDevices: Set<AudioDeviceInfo> = VideoSDK.getAudioDevices()
for (audioDevice in audioDevices) {
Log.d("VideoSDK", "Audio Device's DeviceId " + audioDevice.deviceId)
Log.d("VideoSDK", "Audio Device's Label " + audioDevice.label)
Log.d("VideoSDK", "Audio Device's Kind " + audioDevice.kind)
}
}

private fun getVideoDevices() {
val videoDevices: Set<VideoDeviceInfo> = VideoSDK.getVideoDevices()
for (videoDevice in videoDevices) {
Log.d("VideoSDK", "Video Device's DeviceId " + videoDevice.deviceId)
Log.d("VideoSDK", "Video Device's Label " + videoDevice.label)
Log.d("VideoSDK", "Video Device's Kind " + videoDevice.kind)
}
}

Step 3: Handle Audio Device Changes

  • Implement the onAudioDeviceChanged() callback of the VideoSDK class to dynamically re-render audio device lists whenever new devices are attached or removed from the system.
  • Ensure that users can seamlessly interact with newly connected devices without disruptions.
VideoSDK.setAudioDeviceChangeListener(object : VideoSDK.AudioDeviceChangeEvent {
override fun onAudioDeviceChanged(
selectedAudioDevice: AudioDeviceInfo?,
audioDevices: MutableSet<AudioDeviceInfo>?
) {
Log.d(
"VideoSDK",
"Selected Audio Device: " + selectedAudioDevice.label
)
for (audioDevice in audioDevices) {
Log.d("VideoSDK", "Audio Devices" + audioDevice.label)
}
}
})

Step 4: Ensuring the selected devices are used in the Meeting

  • Ensure that the status of all relevant devices, such as the microphone and camera (on/off), as well as the selected devices, are correctly configured and passed into the meeting from the precall screen.
  • To select a video device, you can either create a custom track with the chosen VideoDeviceInfo and pass it to the initMeeting method of the VideoSDK class, or you can use the setSelectedVideoDevice() method of the VideoSDK class.
  • To select an audio device, use the setSelectedAudioDevice() method of the VideoSDK class.
  • By ensuring this integration, users can seamlessly transition from the precall setup to the actual meeting while preserving their preferred settings.
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val customTracks: MutableMap<String, CustomStreamTrack> = HashMap()

// Specify the video device to use in the meeting
val videoDeviceInfo: VideoDeviceInfo = selectedVideoDeviceInfo

val videoCustomTrack = VideoSDK.createCameraVideoTrack(
"h720p_w960p", "front", CustomStreamTrack.VideoMode.TEXT, true,
this, VideoSDK.getSelectedVideoDevice()
)
customTracks["video"] = videoCustomTrack

VideoSDK.setSelectedVideoDevice(videoDeviceInfo)

// Specify the audio device to use in the meeting
val audioDeviceInfo: AudioDeviceInfo = selectedAudioDeviceInfo

VideoSDK.setSelectedAudioDevice(audioDeviceInfo)

val meeting: Meeting = VideoSDK.initMeeting(
this@MainActivity, "meetingId", "John Due", true,
true, null, null, false, customTracks, null
);
}
}

Step 5: Get Selected Devices

  • VideoSDK library provides two methods, getSelectedVideoDevice() and getSelectedAudioDevice(), which allow us to determine which video and audio devices are currently selected on our Android device.
private fun getSelectedVideoDevice(){
Log.d("TAG", "onCreate: " + VideoSDK.getSelectedVideoDevice().label)
}

private fun getSelectedAudioDevice(){
Log.d("TAG", "onCreate: " + VideoSDK.getSelectedAudioDevice().label)
}

By following these step-by-step instructions, you can seamlessly integrate a precall feature into your application, empowering users to optimize their audio and video setup for a superior communication experience.

note

You can explore the complete implementation of the Precall feature in the official Android SDK example available here.

API Reference

The API references for all the methods utilized in this guide are provided below.

Got a Question? Ask us on discord