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:
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />xmlSet android:required="false" if the app can install on devices without a camera and disable measurement at runtime.
Permission flow
-
Check whether
Manifest.permission.CAMERAis already granted. -
Request permission with the AndroidX Activity Result API if it is missing.
-
Start measurement only after permission is granted.
-
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)
}
}kotlinPreviewView
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,
),
)
}kotlinIf 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()
}kotlinBest practices
- Request permission before the user taps the final scan action.
- Keep the scan screen lifecycle active while measuring.
- Pass an Activity or Fragment
LifecycleOwnerso CameraX can bind and release cleanly. - Show quality guidance from
onQualityStateoronQualityWarning. - 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.
Android can revoke permissions while the app is in the background. Re-check camera permission when the scan screen resumes.
Next Steps
- Methods - Start and cancel measurements
- Configuration - Register quality callbacks
- Error Handling - Handle permission errors