imageUri = contentResolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values) controller.takePicture( ImageCapture .OutputFileOptions .Builder( contentResolver.openOutputStream(imageUri!!)!! ).build(), ContextCompat.getMainExecutor(this), object : ImageCapture.OnImageSavedCallback { override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) { Toast.makeText(this, "Image captured", Toast.LENGTH_SHORT).show() } override fun onError(exception: ImageCaptureException) { Toast.makeText(this, "Image capture failed", Toast.LENGTH_SHORT).show() } }) 20