Class Camera
Entry point for the low-level cross-platform camera API.
This API gives the application direct access to the device camera: live
preview, frame streaming, still capture, video recording, flash and focus
control. It is intended for use cases that the file-based
com.codename1.capture.Capture API cannot serve - real-time barcode
scanning, document boundary detection, custom in-app camera UIs.
Permissions: simply referencing classes in this package causes the build
pipeline to inject NSCameraUsageDescription /
NSMicrophoneUsageDescription (iOS) and android.permission.CAMERA /
android.permission.RECORD_AUDIO plus the CameraX gradle dependencies
(Android). Developers may override the plist strings via the
ios.NSCameraUsageDescription build hint.
Coexistence with Capture: the old com.codename1.capture.Capture
API continues to work unchanged. Both may be used in the same app, but
only one camera consumer may hold the device at a time. Call
CameraSession#pause() before invoking Capture.capturePhoto(...) and
CameraSession#resume() afterwards.
if (Camera.isSupported()) {
CameraSession s = Camera.open(Camera.getDefault(CameraFacing.BACK),
new CameraSessionOptions());
CameraView v = s.createView();
// add v to a Form...
s.setFrameListener(frame -> analyze(frame.getJpegBytes()));
}
For on-device analysis, do not write the frame listener yourself.
com.codename1.ai.vision.VisionCameraView is a component that owns the
session, streams frames into an analyzer with keep-only-the-newest
backpressure, and delivers results on the EDT; and
com.codename1.ai.vision.CodeScanner is an entire barcode scanner screen
in one call. Use this class directly when the application drives the
camera itself -- a custom capture UI, video recording, or torch and zoom
control.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CameraInfo[]Enumerate cameras visible to the platform.static CameraInfogetDefault(CameraFacing facing) Convenience that returns the first camera matching the given facing, ornullif none.static booleanTrue when the running platform has a working camera implementation.static CameraSessionopen(CameraInfo info, CameraSessionOptions opts) Open a camera session.static voidrequestPermissions(boolean audio, SuccessCallback<Boolean> callback) Request runtime permission for camera (and optionally microphone).
-
Method Details
-
isSupported
public static boolean isSupported()True when the running platform has a working camera implementation. False on platforms (or simulator runs) where the camera back-end could not be initialized. -
getCameras
Enumerate cameras visible to the platform. May be empty. -
getDefault
Convenience that returns the first camera matching the given facing, ornullif none. When no facing-specific camera is found and any camera exists, the first available camera is returned. -
open
Open a camera session. ThrowsIllegalStateExceptionif a session is already open; close the old session first. -
requestPermissions
Request runtime permission for camera (and optionally microphone). The callback receivestruewhen both are granted,falseotherwise. On iOS this is a no-op that deliverstrueimmediately; the system prompts the first time the camera is actually started.
-