Index of every page on this site: llms.txt
All skills
android avatar

/camerax

@7f7b217
by androidandroid/skills11k stars
703
Run it yourself

Provide technical guidance for Android camera development with CameraX. Use when implementing camera features, handling asynchronous recording lifecycles, wiring low-level hardware interop using CameraX, or integrating ML Kit or Media3 effects.

Use this Skill: https://skilld.dev/gh/android/skills/camerax

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesfoldables.md

≈884 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Foldable devices introduce unique challenges for camera applications, including dynamic layout changes, multiple display orientations, and physical device postures, such as tabletop and book modes.

Manage fold states and postures

State Posture User interaction Implementation goal
FLAT Standard Full screen preview Conventional mobile phone layout.
HALF_OPENED Tabletop Lower half for controls Split-screen layout, viewfinder on top, controls on bottom.
HALF_OPENED Book Side-by-side Viewfinder on one panel, gallery and controls on the other.

Follow the implementation guide

Detect posture changes

Use the Jetpack WindowManager library to observe the device's hinge state and fold layout.

fun observeFoldingFeature(
    activity: ComponentActivity,
    onFoldChanged: (FoldingFeature?) -> Unit,
) {
    activity.lifecycleScope.launch {
        activity.repeatOnLifecycle(Lifecycle.State.STARTED) {
            WindowInfoTracker.getOrCreate(activity)
                .windowLayoutInfo(activity)
                .collect { layoutInfo ->
                    val foldingFeature = layoutInfo.displayFeatures
                        .filterIsInstance<FoldingFeature>()
                        .firstOrNull()
                    onFoldChanged(foldingFeature)
                }
        }
    }
}
<br />

Handle tabletop mode

In Tabletop mode, horizontal fold, you should move the viewfinder to the top half of the screen and the controls to the bottom half to prevent the user from seeing a "bent" image.

  • Identify orientation: Check FoldingFeature.orientation.
  • Calculate geometry: Use FoldingFeature.bounds to identify the hinge's physical location on the screen.
  • Update UI: Apply padding or constraints to move the PreviewView above the hinge.

Coordinate mapping and Viewport

When the UI layout changes due to a fold, you must update the Viewport to ensure that tap-to-focus and image capture coordinates remain accurate.

/** Rebuild the group and rebind after a fold changes the viewfinder size. */
fun buildUseCaseGroup(
    viewfinder: View,
    preview: Preview,
    imageCapture: ImageCapture,
): UseCaseGroup {
    val rotation = viewfinder.display?.rotation ?: Surface.ROTATION_0
    val viewPort = ViewPort.Builder(Rational(viewfinder.width, viewfinder.height), rotation)
        .setScaleType(ViewPort.FILL_CENTER)
        .build()
    return UseCaseGroup.Builder()
        .addUseCase(preview)
        .addUseCase(imageCapture)
        .setViewPort(viewPort)
        .build()
}
<br />

Rear display mode

Some foldables allow using the rear camera with the cover display while the device is unfolded.

  • Verification: If available through OEM SDKs or Android 14 (API level 34) or higher, check DeviceState.REAR_DISPLAY_STATE.
  • Logic: Handle preview detachment and reattachment on different display surfaces with varying aspect ratios.

Foldable pitfalls

  • Hinge distortion: Don't span the camera preview across a hinge in HALF_OPENED state.
  • Physical orientation: The camera sensor's physical orientation relative to the screen often changes when you fold or unfold the device. Always rely on CameraInfo.getSensorRotationDegrees.
  • Latency: Rebinding UseCase objects during a fold event is expensive. Use the internal scaling of PreviewView before performing a full bindToLifecycle reconfiguration.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts6d3 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill provides technical guidance for Android CameraX development, covering migration from legacy APIs, handling device diversity (foldables, Wear OS, XR), and integrating with ML Kit and Media3. No security issues were detected; all code snippets and external references originate from trusted sources and follow standard platform patterns.

  • Socket6d

    No alerts

  • Snyk7d

    Risk: LOW · No issues

Signed by skilld at 7f7b217. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 1 hour ago.

Activeupdated last week
Other metadata
metadata
{
  "author": "Google LLC",
  "last-updated": "2026-11-10",
  "keywords": [
    "recipe",
    "Android",
    "Camera",
    "Camera1",
    "Camera2",
    "CameraX",
    "migration",
    "Compose",
    "guide",
    "dependencies",
    "PreviewView",
    "CameraXViewfinder",
    "ImageCapture",
    "VideoCapture",
    "ImageAnalysis."
  ]
}

README badge

README badge for android/skills/camerax