Chuyển đến nội dung
Skillpedia
Ứng dụng di động10k · #11908

camerax

Skill này làm gì

Skill này cung cấp hướng dẫn và các mẫu để xây dựng tính năng camera trong ứng dụng Android bằng thư viện CameraX. Nó dành cho lập trình viên Android đang thêm ảnh, video hoặc hiệu ứng vào ứng dụng.

Khi nào nên dùng

  • ✓Khi bạn muốn thêm màn hình camera hoặc quay video vào ứng dụng Android.
  • ✓Khi bạn cần chuyển mã camera cũ của Android sang CameraX.
  • ✓Khi bạn muốn thêm hiệu ứng ML Kit hoặc Media3 vào luồng hình ảnh camera.

Liên kết skill

https://github.com/android/skills/blob/main/camera/camerax/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/android/skills/blob/main/camera/camerax/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Thêm tính năng quay video có âm thanh vào ứng dụng Android của tôi bằng CameraX.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill đưa ra các mẫu từng bước cho thư viện CameraX. Nó chỉ ra các phương thức builder phải được lưu lại thì mới có hiệu lực, và nó bao quát việc tích hợp phần cứng cùng các tích hợp hiệu ứng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

This skill provides procedural guidance and standard patterns for building camera applications on Android, with a focus on CameraX, including its Camera2Interop utilities, and Media3 integrations.

Core workflows

Handling immutable API patterns

Various Android camera and media APIs, especially CameraX VideoCapture, use a fluent, immutable builder-like pattern where methods return a new instance. Failing to reassign these results in settings, such as audio, being ignored.

Pattern: Reassignment is required

// WRONG
run {
  val pending = recorder.prepareRecording(context, opts)
  pending.withAudioEnabled() // This returns a new instance which is ignored
  val active = pending.start(exec, listener)
}

// CORRECT
run {
  val pending = recorder.prepareRecording(context, opts)
      .withAudioEnabled() // Chaining works
  val active = pending.start(exec, listener)
}

// ALSO CORRECT
run {
  var pending = recorder.prepareRecording(context, opts)
  pending = pending.withAudioEnabled() // Reassignment
  val active = pending.start(exec, listener)
}
<br />

See immutability for a list of affected classes.

Migrating to CameraX

When migrating legacy camera codebases to the CameraX Jetpack library:

  • Camera1 to CameraX : For migrating legacy android.hardware.Camera implementations, surface handling, and manual lifecycles, see the Camera1 migration guide.
  • Camera2 to CameraX : For migrating more recent but verbose android.hardware.camera2 implementations, session state callbacks, and interop patterns, see the Camera2 migration guide.

Comprehensive feature blueprinting

For multi-step features that involve multiple files and hardware-level wiring, follow the Structural Blueprinting approach to avoid system timeouts. Such complex features include:

  • Manual controls : Break down into the ViewModel state, the controller layer, and the Camera2Interop wiring in the session.
  • RAW capture: Separate JPEG and RAW output configurations into discrete build steps.
  • Custom effects : Prefer Media3Effect or SurfaceProcessor over manual OpenGL pipelines unless absolute performance is required.
  • Low-light : See low-light for Night Mode and LLB guidance.
  • Foldables : See foldables for handling dynamic postures and hinge states.
  • XR, AR, and VR : See xr for spatial tracking, passthrough synchronization, and latency guardrails.
  • Thermals and power : See thermals for managing StreamUseCase optimizations and PowerManager thermal states.
  • Testing and mocking : See testing for using FakeCameraConfig, handling asynchronous lifecycles, and validating analysis pipelines.
  • ML Kit spatial analysis : See mlkit-spatial for coordinate mapping, rotation logic, and mirrored lens handling.
  • Wear OS camera remote : See wear-os for circular UI constraints, Data Layer API syncing, and remote trigger logic.

See expert-blueprints for step-by-step guides.

API discovery

Always use higher-level abstractions instead of low-level manual wiring:

  • Analysis : Use MlKitAnalyzer instead of manual ImageAnalysis.Analyzer.
  • Filters and effects : Use Media3Effect for standard post-processing.
  • Multi-camera : Use ConcurrentCamera APIs for dual-stream setups.

See modern-apis for current recommendations.

Code quality and architectural rules

Adhere to the following Android ecosystem standard patterns when building your camera implementations:

  • Testing, fakes over mocks : Avoid mocking libraries like Mockito, especially for multi-step CameraX interfaces like ImageProxy. Build "Fakes" to verify state rather than unreliable implementation details.
  • Google Truth assertions : Use assertThat over standard JUnit assertions like assertEquals for improved readability.
  • Explicit test runners : Always define an explicit @RunWith for test classes to ensure the CI environment executes them correctly.
  • Semantic UI merging : When building custom camera controls in Compose, such as a button with an Icon and Text, use `semantics {
Câu hỏi thường gặp

Vì sao cài đặt âm thanh của tôi bị bỏ qua?

Một số phương thức builder của CameraX trả về một đối tượng mới, nên kết quả phải được lưu lại. Skill chỉ ra điều này.

Nó có giúp chuyển từ API Camera cũ không?

Có. Nó có hướng dẫn chuyển mã Camera cũ sang CameraX.

Nó có bao quát ML Kit không?

Có. Nó bao quát việc thêm hiệu ứng ML Kit hoặc Media3 vào thiết lập CameraX.

Chi tiết

Mô tả gốc của tác giả

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.

repo: android/skills

Độ phổ biến

Sao GitHub
10k
Vị trí xếp hạng
#11908
Giấy phép
Apache-2.0
Cập nhật
29/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự