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.

referencesthermals.md

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

Camera operations are among the most power-intensive tasks on mobile devices. Without proactive management, the system throttle hardware, drop frames, or force-close the camera app.

The thermal management strategy

Priority Strategy Implementation
1. Inform Use case hints Provide StreamUseCase to allow the OS to optimize hardware.
2. Monitor Thermal state listener Observe PowerManager.addThermalStatusListener.
3. Act Graceful degradation Dynamically reduce FPS, resolution, or disable demanding effects such as HDR.

Follow the implementation guide

Stream use case optimization

Android 13 (API level 33) introduced StreamUseCase. This is the single most effective way to tell the hardware how to balance quality versus power.

/** Hints the stream use case to the camera HAL (Android 13+, API level 33). */
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
@OptIn(ExperimentalCamera2Interop::class)
fun buildVideoCallPreview(): Preview {
    val builder = Preview.Builder().setTargetName("Preview")
    @Suppress("DEPRECATION") // Deprecated in CameraX 1.7.0 in favor of camera2Interop { }.
    Camera2Interop.Extender(builder).setStreamUseCase(
        CameraMetadata.SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_CALL.toLong()
    )
    return builder.build()
}
<br />

Review the following key use cases for stream optimization:

  • PREVIEW: This option is the default and provides a balanced configuration.
  • STILL_CAPTURE: This option provides high-quality capture for short bursts.
  • VIDEO_RECORD: This option maintains sustained power and is optimized for encoding.
  • VIDEO_CALL: This option minimizes power consumption for long-duration sessions.

Monitor thermal status

Don't wait for a crash. Monitor the PowerManager status and react before THERMAL_STATUS_CRITICAL.

/** Requires Android 10 (API level 29) or higher. */
@RequiresApi(Build.VERSION_CODES.Q)
fun registerThermalListener(context: Context): PowerManager.OnThermalStatusChangedListener {
    val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
    val listener = PowerManager.OnThermalStatusChangedListener { status ->
        when (status) {
            PowerManager.THERMAL_STATUS_MODERATE -> {
                // Signal to UI: "Device is warming up"
            }
            PowerManager.THERMAL_STATUS_SEVERE -> {
                // ACTION: Reduce Frame Rate from 60fps to 30fps
                // ACTION: Disable HDR or High-Quality Post-processing
            }
            PowerManager.THERMAL_STATUS_CRITICAL -> {
                // ACTION: Close the camera session to prevent hardware damage
            }
        }
    }
    powerManager.addThermalStatusListener(listener)
    return listener // Remove it with removeThermalStatusListener when done.
}
<br />

Graceful degradation tiers

Tier Action User impact
Mild Stop background analysis using ML Kit Minimal
Moderate Cap frame rate to 30 FPS Noticeable but smooth
Severe Drop resolution from 1080p to 720p Significant visual change
Critical Shut down the session App unusable in safe mode

Thermal pitfalls

  • The "double work" bug: Don't run two high-resolution streams---such as a preview and a video capture stream---at different aspect ratios unless necessary. This forces the image signal processor (ISP) to perform double the scaling work, which generates excessive heat.
  • Surface overload : Don't use multi-step SurfaceProcessor or Media3Effect chains during THERMAL_STATUS_SEVERE.
  • Flash heat : Flash or torch usage generates high thermal load. Proactively disable the flash if thermal status is SEVERE.

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