Android.Hardware.Camera2.CameraManager.OpenCamera Method
Open a connection to a camera with the given ID.

Syntax

[Android.Runtime.Register("openCamera", "(Ljava/lang/String;Landroid/hardware/camera2/CameraDevice$StateCallback;Landroid/os/Handler;)V", "")]
public void OpenCamera (string cameraId, CameraDevice.StateCallback callback, Android.OS.Handler handler)

See Also

CameraManager.GetCameraIdList
Android.App.Admin.DevicePolicyManager.SetCameraDisabled(Android.Content.ComponentName, System.Boolean)

Parameters

cameraId
The unique identifier of the camera device to open
callback
The callback which is invoked once the camera is opened
handler
The handler on which the callback should be invoked, or null to use the current thread's Android.OS.Looper.

Exceptions

TypeReason
Android.Hardware.Camera2.CameraAccessExceptionif the camera is disabled by device policy, or the camera has become or was disconnected.
Java.Lang.IllegalArgumentExceptionif cameraId or the callback was null, or the cameraId does not match any currently or previously available camera device.
Java.Lang.SecurityExceptionif the application does not have permission to access the camera

Remarks

Open a connection to a camera with the given ID.

Use CameraManager.GetCameraIdList to get the list of available camera devices. Note that even if an id is listed, open may fail if the device is disconnected between the calls to CameraManager.GetCameraIdList and CameraManager.OpenCamera(string, .StateCallback, .StateCallback).

Once the camera is successfully opened, NoType:android/hardware/camera2/CameraDevice$StateCallback;Href=../../../../reference/android/hardware/camera2/CameraDevice.StateCallback.html#onOpened(android.hardware.camera2.CameraDevice) will be invoked with the newly opened Android.Hardware.Camera2.CameraDevice. The camera device can then be set up for operation by calling CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler) and CameraDevice.CreateCaptureRequest(CameraTemplate)

If the camera becomes disconnected during initialization after this function call returns, NoType:android/hardware/camera2/CameraDevice$StateCallback;Href=../../../../reference/android/hardware/camera2/CameraDevice.StateCallback.html#onDisconnected(android.hardware.camera2.CameraDevice) with a Android.Hardware.Camera2.CameraDevice in the disconnected state (and NoType:android/hardware/camera2/CameraDevice$StateCallback;Href=../../../../reference/android/hardware/camera2/CameraDevice.StateCallback.html#onOpened(android.hardware.camera2.CameraDevice) will be skipped).

If opening the camera device fails, then the device callback's NoType:android/hardware/camera2/CameraDevice$StateCallback;Href=../../../../reference/android/hardware/camera2/CameraDevice.StateCallback.html#onError(android.hardware.camera2.CameraDevice, int) method will be called, and subsequent calls on the camera device will throw a Android.Hardware.Camera2.CameraAccessException.

[Android Documentation]

Requirements

Namespace: Android.Hardware.Camera2
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0