Skip to content

Camera & Permissions

The Android SDK uses the front camera through CameraX. Your app must request camera permission before calling measureVitals().

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" />

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

  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)
}
}

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,
),
)
}

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

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

val capabilities = sdk.getDeviceCapabilities()
when {
!capabilities.hasCamera -> showMessage("No camera found on this device.")
!capabilities.hasFrontCamera -> showMessage("A front camera is required.")
!capabilities.cameraPermissionGranted -> requestCameraPermission()
else -> startMeasurement()
}
  • 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.