CameraUtil

object CameraUtil

Utility class for querying the camera's support.

Samples

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.miteksystems.misnap.apputil.LicenseFetcher
import com.miteksystems.misnap.camera.util.CameraUtil
import com.miteksystems.misnap.core.MiSnapSettings
fun main() { 
   //sampleStart 
   /**
 * This example demonstrates how to query the device's camera support in advance before invoking the
 * MiSnap SDK. This is a recommended best practice for every MiSnap SDK integration as it makes the
 * help screen asset selection faster.
 *
 * NOTE: Ensure that the provided license has all the necessary features enabled for the target
 *  MiSnap session.
 */
class CameraSupport : Fragment() {

    /**
     * Fetch the Misnap SDK license.
     * Good practice: Handle the license in a way that it is remotely updatable.
     */
    private val license by lazy {  
        LicenseFetcher.fetch()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        /**
         * Keep in mind that the camera requirements may be different depending on the [MiSnapSettings.UseCase];
         * a standard face session would evaluate front facing cameras while a document session would
         * evaluate back facing cameras.
         * If you plan to integrate a combined workflow that uses both front and back facing cameras
         * make sure to query the support for both.
         */
        val settings = MiSnapSettings(MiSnapSettings.UseCase.ID_FRONT, license)

        // Request the camera support and register a listener to get the results.
        CameraUtil.findSupportedCamera(requireContext(), viewLifecycleOwner, settings.camera) {
            when (it) {
                is CameraUtil.CameraSupportResult.Success -> {
                    // Preset the trigger mode to simplify the help screen asset selection.
                    settings.analysis.document.trigger =
                        if (it.cameraInfo.supportsAutoAnalysis) {
                            MiSnapSettings.Analysis.Document.Trigger.AUTO
                        } else {
                            MiSnapSettings.Analysis.Document.Trigger.MANUAL
                        }
                }
                is CameraUtil.CameraSupportResult.Error -> {
                    /**
                     * The device's camera is not supported for the requested [MiSnapSettings.UseCase].
                     */
                }
            }
        }
    }
} 
   //sampleEnd
}

Types

Link copied to clipboard
sealed class CameraSupportResult

Results returned by findSupportedCamera when CameraUtil is used to pre select a camera.

Functions

Link copied to clipboard
fun findSupportedCamera(context: Context, lifecycleOwner: LifecycleOwner, cameraSettings: MiSnapSettings.Camera, cameraSupportResultListener: (result: CameraUtil.CameraSupportResult) -> Unit)

Tries to find a camera to use according to the requirements of the supplied filter.