Android: 如何在仿真器中使用摄像头?

通过将 AVD 管理器中的前置摄像头设置为“ webcam0”,我将一个摄像头连接到我的模拟器上。当我启动模拟器的相机应用程序时,我得到了错误

CameraService::connect X (pid 702) rejected (invalid cameraId 0).

下面是 Android 源代码的相关部分:

sp<ICamera> CameraService::connect(
const sp<ICameraClient>& cameraClient, int cameraId) {


int callingPid = getCallingPid();


[...]


if (cameraId < 0 || cameraId >= mNumberOfCameras) {
LOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).",
callingPid, cameraId);
return NULL;
}


[...]
}

摄像头已经被正确地分配了一个 ID 为0,因为只有一个摄像头。然而,mNumberOfCameras大概仍然是0。这意味着摄像头已经被模拟器注册了,但是它并没有更新连接的摄像头的数量。

我如何连接一个网络摄像头,以便它将被模拟器正确识别?

编辑: \android-sdks\tools中的命令 emulator -webcam-list -avd <name of your AVD>给出结果:

List of web cameras connected to the computer:
Camera `webcam0` is connected to device `AndroidEmulatorVC0` on channel 0 using pixel format `BGR4`

当我从 Eclipse 的 AVD 管理器或使用 emulator -camera-front webcam0 -avd <name of your AVD>启动网络摄像头时,我得到以下窗口:

enter image description here

编辑2: 这似乎是模拟器中的一个 bug。建议的答案告诉你如何安装摄像机,但不能解决我的问题。我最终用一台内置摄像头的笔记本电脑解决了这个问题。也许另一个 USB 摄像头也可以工作。

156923 次浏览

Follow the below steps in Eclipse.

  1. Goto -> AVD Manager
  2. Create/Edit the AVD.
  3. Hardware > New:
  4. Configures camera facing back
  5. Click on the property value and choose = "webcam0".
  6. Once done all the above the webcam should be connected. If it doesnt then you need to check your WebCam drivers.

Check here for more information : How to use web camera in android emulator to capture a live image?

enter image description here

UPDATE

In Android Studio AVD:

  1. Open AVD Manager:

AVD menu

  1. Add/Edit AVD:

Specific AVD strip

  1. Click Advanced Settings in the bottom of the screen:

AVD Advanced Settings

  1. Set your camera of choice as the front/back cameras:

AVD Camera Settings