检查设备有一个摄像头?有一个、摄像头、设备

2023-09-12 08:32:53 作者:巴黎鐵塔為你留下的風景、

在我的应用程序,我想用相机,如果设备有一个。是否有运行Android的的的任何设备不的有一个摄像头?通过包括以下到我的清单:

In my app, I'd like to use the camera, if the device has one. Are there any devices running android that do not have a camera? By including the following into my manifest:

<uses-feature android:name="android.hardware.camera" android:required="false"/>

然后它基本上说:我会用相机如果存在,但并不需要一个运行应用程序。

then it's basically saying "I'll use a camera if one exists, but don't need one to run the app".

怎么能检查是否存在摄像头的设备上,试图用相机前级?

How could I check if a camera exists on the device, before attempting to use the Camera class?

推荐答案

我还没有尝试过,但是:

I've not tried it, but:

private android.hardware.Camera mCameraDevice;

try {
  mCameraDevice = android.hardware.Camera.open();
} catch (RuntimeException e) {
  Log.e(TAG, "fail to connect Camera", e);
  // Throw exception
}

可能是你所需要的。

May be what you need.