本文介绍了如何检查相机的任何应用程序中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法来检查,如果相机是开放与否?我不想打开摄像头,我只是想的检查其状态的。

Is there any way to check if the camera is open or not? I don't want to open the camera, I just want to check its status.

推荐答案

您可以检查它的使用方法 Camera.open(cameraId)

You can check it using method Camera.open(cameraId).

创建一个新的Camera对象访问特定的硬件摄像头。如果相同的相机被其他应用程序打开,这将抛出一个RuntimeException。

Creates a new Camera object to access a particular hardware camera. If the same camera is opened by other applications, this will throw a RuntimeException.

抛出  RuntimeException的
  如果打开相机失败(例如,如果相机是由另一个进程或设备的策略管理器的使用已禁用摄像头)。

更新:

例如:

public boolean isCameraUsebyApp() {
    Camera camera = null;
    try {
        camera = Camera.open();
    } catch (RuntimeException e) {
        return true;
    } finally {
        if (camera != null) camera.release();
    }
    return false;
}

您可以使用此方法使用作为保建议,但记住这件事记住,此方法首先获取摄像机。

You can use this method to use as Paul suggested but keep this thing in mind that this method first acquire the camera.

如果其获取成功那么它意味着没有其他应用程序正在使用这台相机,不要忘了再次释放它,否则你将无法再得到它。

If its acquire successfully then its mean that no other application is using this camera and don't forgot to release it again otherwise you will not able to acquire it again.

其旗下抛出的RuntimeException 这意味着摄像机正被另一个进程或设备的策略管理器的使用已禁用摄像头。

Its its throws RuntimeException it means that camera is in use by another process or device policy manager has disabled the camera.

这篇关于如何检查相机的任何应用程序中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 01:44