Permission Requests

Rendering video and audio calls necessitates Android Runtime Permissions, which are essential for accessing the camera and microphone. Therefore, you must request Android Runtime permissions to use the camera or microphone, as applicable, before joining a call using the call.join function. This step ensures your application adheres to Android’s security standards.

The simplest method to request Android Runtime permissions is by using the LaunchCallPermissions API before invoking the join method. Here’s an example of how to do this:

val call = client.call(type = "default", id = callId)
LaunchCallPermissions(call = call) {
    // this lambda function will be executed after all the permissions are granted.
    call.join(create = true)
}

Then you’ll see the result below before joing the call:

Call Lobby with permission

If you want to request permissions without using the LaunchCallPermissions API, you can achieve it by using rememberCallPermissionsState seamlessly.

val permissionState = rememberCallPermissionsState(call = call)
val allPermissionGranted = permissionState.allPermissionsGranted

Button(onClick = { permissionState.launchPermissionRequest() }) {
    Text(text = "Request permissions")
}

// once all the reuqest permissions have been granted, join the call.
LaunchedEffect(key1 = allPermissionGranted) {
    if (allPermissionGranted){
        call.join(create = true)
    }
}

Request Multiple Permissions

rememberCallPermissionsState is built with accompanist under the hood, so it also provides similar functions. You can tweak the list of permissions that you want to request by giving the permission parameter.

val permissionState = rememberCallPermissionsState(
    call = call,
    permissions = listOf(
        android.Manifest.permission.CAMERA,
        android.Manifest.permission.RECORD_AUDIO,
        .. // more!
    )
)

You can also handle whether each permission was granted or not like the example below:

val permissionState = rememberCallPermissionsState(
    call = call,
    permissions = listOf(
        android.Manifest.permission.CAMERA,
        android.Manifest.permission.RECORD_AUDIO,
    )
) {
    if (it[android.Manifest.permission.CAMERA] == true) {
        call.camera.setEnabled(true)
    } else {
        // shows a toast or dialog
    }

    if (it[android.Manifest.permission.RECORD_AUDIO] == true) {
        call.microphone.setEnabled(true)
    } else {
        // shows a toast or dialog
    }
}

So you can execute some additional tasks if a user grants permission, or display a toast message or popup dialog if a user denies permissions.

Request a Single Permission

You can also simply request a single permission for a camera and microphone like the example below:

// request a camera permission
val cameraPermissionState = rememberCameraPermissionState(call = call)
cameraPermissionState.launchPermissionRequest()

// request a microphone permission
val microphonePermissionState = rememberMicrophonePermissionState(call = call)
microphonePermissionState.launchPermissionRequest()
© Getstream.io, Inc. All Rights Reserved.