Camera & Microphone
This content is for v1.2.0. Switch to the latest version for up-to-date documentation.
ZKite 1.2.0 enables native multimedia capture without requiring camera boilerplate or custom Java classes. Capture full-resolution photos, record videos, control the hardware torch, and record microphone audio with duration limits.
Taking Photos & Videos
Section titled “Taking Photos & Videos”To capture photos or videos, ZKite delegates capture to the user’s preferred installed Android camera application:
from zkite import camera
# 1. Take a full-resolution photophoto = await camera.capture()if photo: print(f"Captured photo: {photo.name} ({photo.size} bytes)") # Captured photo resides in files.cache_dir(); copy if permanent: # await photo.copy_to(permanent_path)
# 2. Record a video with an optional maximum duration limitvideo = await camera.record_video(duration=30)if video: print(f"Captured video clip: {video.name}")Advantages of Intent-Based Capture
Section titled “Advantages of Intent-Based Capture”- Full Sensor Resolution: ZKite provides the camera app with a temporary output file URI, ensuring the camera delivers the full optical sensor resolution—not an impoverished thumbnail.
- Familiar User Controls: Users enjoy their phone’s native camera features (HDR, optical zoom, flash control, night mode, portrait blur) without any implementation complexity in your app.
- No
CAMERAManifest Permission Required: Because capture is delegated to the system camera app via standard Android intents, your app does not need the dangerousandroid.permission.CAMERAmanifest permission.
Flashlight Torch Control
Section titled “Flashlight Torch Control”Control the device’s rear flashlight through camera.torch:
from zkite import camera
# Turn flashlight onawait camera.torch(True)
# Turn flashlight offawait camera.torch(False)- Automatic Cleanup: For safety and battery conservation, the flashlight turns off automatically when your app leaves the foreground.
- Hardware Detection: If the device lacks a camera flash, calling
camera.torch(True)raisesUnsupportedFeature.
Microphone Recording
Section titled “Microphone Recording”Record voice notes, interviews, or memos using Android’s hardware audio encoder:
from zkite import audiofrom zkite.errors import DeviceError, PermissionDenied
async def record_voice_clip(): try: # Starts recording in AAC/M4A format recording = await audio.record(max_seconds=60)
# ... user performs action or taps 'Stop' ...
# Stop and finalize recording into a FileRef clip = await recording.stop() print(f"Audio saved to: {clip.path}") return clip except PermissionDenied: print("Microphone access was denied by the user") except DeviceError as exc: print(f"Recording error: {exc}")Discarding a Recording
Section titled “Discarding a Recording”To cancel and discard an active recording without saving:
await recording.cancel()Recording Lifecycle & Constraints
Section titled “Recording Lifecycle & Constraints”- Audio Format: Recorded using the platform-standard AAC encoder packaged in an MPEG-4 (
.m4a) container. - Automatic Permissions: Using
audio.record()causes the static scanner to declareRECORD_AUDIOinapp.jsonand triggers Android’s runtime microphone permission prompt. - Foreground Lifecycle: Audio recording automatically terminates if the application is backgrounded or when another app assumes microphone focus.
- Minimum Duration: Extremely short recordings (< 0.2s) or aborted recordings raise a descriptive
DeviceError. - Privacy Indicators: Android 12+ green status bar privacy indicators and system microphone toggles are fully respected. If the user disabled microphone access in global system settings,
ResourceBusyorPermissionDeniedis raised.
