public class

CameraUnavailableException

extends java.lang.Exception

 java.lang.Object

↳java.lang.Throwable

↳java.lang.Exception

↳androidx.camera.core.CameraUnavailableException

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-core', version: '1.2.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-core
  • version: 1.2.0-alpha01

Artifact androidx.camera:camera-core:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

CameraUnavailableException is thrown when a camera device could not be queried or opened or if the connection to an opened camera device is no longer valid.

Summary

Fields
public static final intCAMERA_DISABLED

The camera is disabled due to a device policy, and cannot be opened.

public static final intCAMERA_DISCONNECTED

The camera device is removable and has been disconnected from the Android device, or the camera service has shut down the connection due to a higher-priority access request for the camera device.

public static final intCAMERA_ERROR

The camera device is currently in the error state.

public static final intCAMERA_IN_USE

The camera device is in use already.

public static final intCAMERA_MAX_IN_USE

The system-wide limit for number of open cameras or camera resources has been reached, and more camera devices cannot be opened.

public static final intCAMERA_UNAVAILABLE_DO_NOT_DISTURB

The camera is unavailable due to .

public static final intCAMERA_UNKNOWN_ERROR

Some other error occurred.

Constructors
publicCameraUnavailableException(int reason)

publicCameraUnavailableException(int reason, java.lang.String message)

publicCameraUnavailableException(int reason, java.lang.String message, java.lang.Throwable cause)

publicCameraUnavailableException(int reason, java.lang.Throwable cause)

Methods
public intgetReason()

The reason the camera is unavailable.

from java.lang.ThrowableaddSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Fields

public static final int CAMERA_UNKNOWN_ERROR

Some other error occurred.

public static final int CAMERA_DISABLED

The camera is disabled due to a device policy, and cannot be opened.

public static final int CAMERA_DISCONNECTED

The camera device is removable and has been disconnected from the Android device, or the camera service has shut down the connection due to a higher-priority access request for the camera device.

public static final int CAMERA_ERROR

The camera device is currently in the error state.

The camera has failed to open or has failed at a later time as a result of some non-user interaction.

public static final int CAMERA_IN_USE

The camera device is in use already.

public static final int CAMERA_MAX_IN_USE

The system-wide limit for number of open cameras or camera resources has been reached, and more camera devices cannot be opened.

public static final int CAMERA_UNAVAILABLE_DO_NOT_DISTURB

The camera is unavailable due to . Some API 28 devices cannot access the camera when the device is in "Do Not Disturb" mode. The camera will not be accessible until "Do Not Disturb" mode is disabled.

See also:

Constructors

public CameraUnavailableException(int reason)

public CameraUnavailableException(int reason, java.lang.String message)

public CameraUnavailableException(int reason, java.lang.String message, java.lang.Throwable cause)

public CameraUnavailableException(int reason, java.lang.Throwable cause)

Methods

public int getReason()

The reason the camera is unavailable.

Source

/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.core;

import android.app.NotificationManager;

import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * {@code CameraUnavailableException} is thrown when a camera device could not be queried or opened
 * or if the connection to an opened camera device is no longer valid.
 */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public class CameraUnavailableException extends Exception {

    /**
     * Some other error occurred.
     */
    public static final int CAMERA_UNKNOWN_ERROR = 0;

    /**
     * The camera is disabled due to a device policy, and cannot be opened.
     */
    public static final int CAMERA_DISABLED = 1;

    /**
     * The camera device is removable and has been disconnected from the Android device, or the
     * camera service has shut down the connection due to a higher-priority access request for the
     * camera device.
     */
    public static final int CAMERA_DISCONNECTED = 2;

    /**
     * The camera device is currently in the error state.
     *
     * <p>The camera has failed to open or has failed at a later time as a result of some
     * non-user interaction.
     */
    public static final int CAMERA_ERROR = 3;


    /**
     * The camera device is in use already.
     */
    public static final int CAMERA_IN_USE = 4;

    /**
     * The system-wide limit for number of open cameras or camera resources has been reached, and
     * more camera devices cannot be opened.
     */
    public static final int CAMERA_MAX_IN_USE = 5;

    /**
     * The camera is unavailable due to {@link NotificationManager.Policy}. Some API 28 devices
     * cannot access the camera when the device is in "Do Not Disturb" mode. The camera will not
     * be accessible until "Do Not Disturb" mode is disabled.
     *
     * @see NotificationManager#getCurrentInterruptionFilter()
     * @see NotificationManager#ACTION_INTERRUPTION_FILTER_CHANGED
     */
    public static final int CAMERA_UNAVAILABLE_DO_NOT_DISTURB = 6;

    /** @hide */
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {
            CAMERA_UNKNOWN_ERROR,
            CAMERA_DISABLED,
            CAMERA_DISCONNECTED,
            CAMERA_ERROR,
            CAMERA_IN_USE,
            CAMERA_MAX_IN_USE,
            CAMERA_UNAVAILABLE_DO_NOT_DISTURB
    })
    public @interface Reason {}

    private final int mReason;

    public CameraUnavailableException(@Reason int reason) {
        super();
        mReason = reason;
    }

    public CameraUnavailableException(@Reason int reason, @Nullable String message) {
        super(message);
        mReason = reason;
    }

    public CameraUnavailableException(@Reason int reason, @Nullable String message,
            @Nullable Throwable cause) {
        super(message, cause);
        mReason = reason;
    }

    public CameraUnavailableException(@Reason int reason, @Nullable Throwable cause) {
        super(cause);
        mReason = reason;
    }

    /** The reason the camera is unavailable. */
    @Reason
    public int getReason() {
        return mReason;
    }
}