Circadify

Camera & Permissions

Request camera permission and attach a CameraX PreviewView for the Circadify Android SDK.

The Android SDK captures from the front camera through CameraX by default, and can use the rear camera when you set cameraLensFacing = CameraLensFacing.BACK on the config. Your app must request camera permission before calling measureVitals().

Manifest

Add camera and internet permissions to the host app manifest:

AndroidManifest.xml
<uses-feature android:name="android.hardware.camera" android:required="false" />
 
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
xml

Set android:required="false" if the app can install on devices without a camera and disable measurement at runtime.

Permission flow

  1. Check whether Manifest.permission.CAMERA is already granted.

  2. Request permission with the AndroidX Activity Result API if it is missing.

  3. Start measurement only after permission is granted.

  4. Handle denial with a clear message or a link to app settings.

private val permissionLauncher = registerForActivityResult(
    ActivityResultContracts.RequestPermission(),
) { granted ->
    if (granted) {
        startMeasurement()
    } else {
        showMessage("Camera permission is required to measure vitals.")
    }
}
 
private fun startWhenAllowed() {
    val granted = ContextCompat.checkSelfPermission(
        this,
        Manifest.permission.CAMERA,
    ) == PackageManager.PERMISSION_GRANTED
 
    if (granted) {
        startMeasurement()
    } else {
        permissionLauncher.launch(Manifest.permission.CAMERA)
    }
}
kotlin

PreviewView

The SDK is headless. Pass a caller-owned PreviewView if you want a live camera preview.

val previewView = PreviewView(this).apply {
    scaleType = PreviewView.ScaleType.FILL_CENTER
}
 
lifecycleScope.launch {
    val result = sdk.measureVitals(
        MeasurementOptions(
            lifecycleOwner = this@MainActivity,
            previewView = previewView,
        ),
    )
}
kotlin

If you pass previewView = null, the SDK still captures frames, but your app will not show a camera preview.

Capability checks

Use getDeviceCapabilities() before showing scan UI on unsupported devices.

val capabilities = sdk.getDeviceCapabilities()
 
// Require the lens you'll actually capture from: hasFrontCamera for the default
// front camera, or hasBackCamera when you set cameraLensFacing = CameraLensFacing.BACK.
val lensAvailable = when (config.cameraLensFacing) {
    CameraLensFacing.FRONT -> capabilities.hasFrontCamera
    CameraLensFacing.BACK -> capabilities.hasBackCamera
}
 
when {
    !capabilities.hasCamera -> showMessage("No camera found on this device.")
    !lensAvailable -> showMessage("The selected camera is not available on this device.")
    !capabilities.cameraPermissionGranted -> requestCameraPermission()
    else -> startMeasurement()
}
kotlin

Best practices

  • Request permission before the user taps the final scan action.
  • Keep the scan screen lifecycle active while measuring.
  • Pass an Activity or Fragment LifecycleOwner so CameraX can bind and release cleanly.
  • Show quality guidance from onQualityState or onQualityWarning.
  • Call sdk.cancel() or cancel the coroutine when the user leaves the scan screen.
  • Call sdk.destroy() when the SDK instance is no longer needed.
Note

Android can revoke permissions while the app is in the background. Re-check camera permission when the scan screen resumes.

Next Steps