如何检查相机是否被任何应用程序打开 [英] How to check if camera is opened by any application

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

问题描述

有没有办法检查相机是否打开?我不想打开相机,我只想检查它的状态.

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)查看.

创建一个新的相机对象来访问特定的硬件相机.如果同一个相机被其他应用程序打开,这将抛出一个 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.

投掷运行时异常
如果打开摄像头失败(例如,如果摄像头正在被另一个进程使用或设备策略管理器已禁用摄像头).

Throws RuntimeException
If opening the camera fails (For Example, if the camera is in use by another process or device policy manager has disabled the camera).

更新:

例子:

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

您可以按照 Paul 的建议使用此方法,但请记住,此方法首先获取相机.

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆