public final class Camera

  1. Object
  2. 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.

Methods

public static boolean isSupported()True when the running platform has a working camera implementation.
public static CameraInfo[] getCameras()Enumerate cameras visible to the platform.
public static CameraInfo getDefault(CameraFacing facing)Convenience that returns the first camera matching the given facing, or null if none.
public static CameraSession open(CameraInfo info, CameraSessionOptions opts)Open a camera session.
public static void requestPermissions(boolean audio, SuccessCallback<Boolean> callback)Request runtime permission for camera (and optionally microphone).

Inherited methods

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

public static CameraInfo[] getCameras()
Enumerate cameras visible to the platform. May be empty.

getDefault

public static CameraInfo getDefault(CameraFacing facing)
Convenience that returns the first camera matching the given facing, or null if none. When no facing-specific camera is found and any camera exists, the first available camera is returned.

open

public static CameraSession open(CameraInfo info, CameraSessionOptions opts)
Open a camera session. Throws IllegalStateException if a session is already open; close the old session first.

requestPermissions

public static void requestPermissions(boolean audio, SuccessCallback<Boolean> callback)
Request runtime permission for camera (and optionally microphone). The callback receives true when both are granted, false otherwise. On iOS this is a no-op that delivers true immediately; the system prompts the first time the camera is actually started.