Android 任何模拟器的相机不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20715655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Camera of any emulator not working
提问by GrIsHu
Friends
朋友们
I am facing this issue since so long but i am able to get any kind of solution to get working camera in emulator. I have gone through all the answer of the SO but none helped me uptill now.
这么久以来我一直面临这个问题,但我能够获得任何类型的解决方案来在模拟器中使用工作相机。我已经完成了 SO 的所有答案,但直到现在都没有帮助我。
If i create any emulator with any api but in none of my emulator camera application does not work. So i am not able to test any of the application which contains camera functionality. I guess may be its happening because of the hardware configuration of my system. But i am not sure about it.
如果我使用任何 api 创建任何模拟器,但在我的模拟器相机应用程序中没有一个不起作用。所以我无法测试任何包含相机功能的应用程序。我想可能是由于我系统的硬件配置而发生的。但我不确定。
I do not know why this issue occurs. Please help me to solve and find out the reason for the issue.
我不知道为什么会出现这个问题。请帮我解决并找出问题的原因。
Here is the error which i get whenever i starts camera in emulator.
这是我在模拟器中启动相机时得到的错误。
12-21 00:04:58.100: E/CameraService(55): CameraService::connect X (pid 2604) rejected (invalid cameraId 0).
12-21 00:04:58.110: W/CameraBase(2604): An error occurred while connecting to camera: 0
12-21 00:04:58.110: E/CameraHolder(2604): fail to connect Camera
12-21 00:04:58.110: E/CameraHolder(2604): java.lang.RuntimeException: Fail to connect to camera service
12-21 00:04:58.110: E/CameraHolder(2604): at android.hardware.Camera.native_setup(Native Method)
12-21 00:04:58.110: E/CameraHolder(2604): at android.hardware.Camera.<init>(Camera.java:350)
12-21 00:04:58.110: E/CameraHolder(2604): at android.hardware.Camera.open(Camera.java:309)
12-21 00:04:58.110: E/CameraHolder(2604): at com.android.camera.CameraHolder.open(CameraHolder.java:131)
12-21 00:04:58.110: E/CameraHolder(2604): at com.android.camera.Util.openCamera(Util.java:267)
12-21 00:04:58.110: E/CameraHolder(2604): at com.android.camera.Camera.run(Camera.java:1100)
12-21 00:04:58.110: E/CameraHolder(2604): at java.lang.Thread.run(Thread.java:841)
12-21 00:04:58.110: W/dalvikvm(2604): threadid=11: thread exiting with uncaught exception (group=0xb4a29b90)
12-21 00:04:58.120: E/AndroidRuntime(2604): FATAL EXCEPTION: Thread-117
12-21 00:04:58.120: E/AndroidRuntime(2604): Process: com.android.camera, PID: 2604
12-21 00:04:58.120: E/AndroidRuntime(2604): java.lang.RuntimeException: openCamera failed
12-21 00:04:58.120: E/AndroidRuntime(2604): at com.android.camera.Util.openCamera(Util.java:272)
12-21 00:04:58.120: E/AndroidRuntime(2604): at com.android.camera.Camera.run(Camera.java:1100)
12-21 00:04:58.120: E/AndroidRuntime(2604): at java.lang.Thread.run(Thread.java:841)
12-21 00:04:58.120: E/AndroidRuntime(2604): Caused by: com.android.camera.CameraHardwareException: java.lang.RuntimeException: Fail to connect to camera service
12-21 00:04:58.120: E/AndroidRuntime(2604): at com.android.camera.CameraHolder.open(CameraHolder.java:135)
12-21 00:04:58.120: E/AndroidRuntime(2604): at com.android.camera.Util.openCamera(Util.java:267)
12-21 00:04:58.120: E/AndroidRuntime(2604): ... 2 more
12-21 00:04:58.120: E/AndroidRuntime(2604): Caused by: java.lang.RuntimeException: Fail to connect to camera service
12-21 00:04:58.120: E/AndroidRuntime(2604): at android.hardware.Camera.native_setup(Native Method)
12-21 00:04:58.120: E/AndroidRuntime(2604): at android.hardware.Camera.<init>(Camera.java:350)
12-21 00:04:58.120: E/AndroidRuntime(2604): at android.hardware.Camera.open(Camera.java:309)
12-21 00:04:58.120: E/AndroidRuntime(2604): at com.android.camera.CameraHolder.open(CameraHolder.java:131)
12-21 00:04:58.120: E/AndroidRuntime(2604): ... 3 more
Below are the options which i get while i am trying to edit emulator.
以下是我在尝试编辑模拟器时得到的选项。
Thanks.
谢谢。
回答by GrIsHu
I have resolved my issue by changing the emulators "Back Camera"
property to Emulatedas shown in screenshot.
我通过将模拟器"Back Camera"
属性更改为Emulated解决了我的问题,如屏幕截图所示。
回答by ?smail Aygün
Open Tools->Android->AVD Manager then click edit for your virtual device.Click Show Advanced Settings on your virtual device configuration window.Then camera settings field is turned on,select Emulated Front and Back.That is it.
打开工具->Android->AVD 管理器,然后单击您的虚拟设备的编辑。单击虚拟设备配置窗口上的显示高级设置。然后打开相机设置字段,选择模拟正面和背面。就是这样。
回答by Khalil Laleh
I'm using Android Studio 3.1.1 in ubuntu 16.04 and had the same issue.
So after couple of days googling, finally solved my problem by myself.
The Solution was:
我在 ubuntu 16.04 中使用 Android Studio 3.1.1 并且遇到了同样的问题。
所以经过几天的谷歌搜索,终于自己解决了我的问题。解决方案是:
- Edit the AVD and set the Emulated Performance/Graphicsfrom Automaticto Software - GLES 1.1.
- Changed the SD Cardsize to 256 MB.
- Set only one of camera (e.g. Front) to webcam0 and other one to none or emulated.
- 编辑 AVD 并将仿真性能/图形从自动设置为软件 - GLES 1.1。
- 将SD 卡大小更改为256 MB。
- 仅将一个摄像头(例如 Front)设置为 webcam0,将另一个设置为无或模拟。
Hope this helps others with the same problem.
希望这可以帮助其他有同样问题的人。
回答by Bhoomika Brahmbhatt
There is no declaration about Camera in limitation of Emulator in doc.
doc中 Emulator 的限制中没有关于 Camera 的声明。
You can Enable camera in Emulator.But emulator wont show a realtime camera regardless.
您可以在 Emulator 中启用相机。但无论如何,模拟器都不会显示实时相机。
As of Android SDK version 14, the emulator supports webcams to simulate a camera:
从Android SDK 版本 14 开始,模拟器支持网络摄像头来模拟摄像头:
General notes - Added webcam support to Android 4.0 or later platforms to emulate rear-facing cameras when one webcam is present, and to emulate both rear-facing and front-facing cameras when two webcams are present. Webcam suport is for Windows and Linux only. Mac support will come in a later release.
一般说明 - 向 Android 4.0 或更高版本平台添加了网络摄像头支持,以在存在一个网络摄像头时模拟后置摄像头,并在存在两个网络摄像头时模拟后置和前置摄像头。网络摄像头支持仅适用于 Windows 和 Linux。Mac 支持将在以后的版本中提供。
回答by Shubham Gupta Ggps
JUST DO THIS
就这样做
use emulated in both Front and back and then chage sdcard size
在正面和背面使用模拟,然后更改 sdcard 大小
回答by Looking Forward
From the android documentation:
从安卓文档:
Emulator Limitations
模拟器限制
No support for camera/video capture In other words, no, you cannot access or preview the camera in the emulator.
不支持摄像头/视频捕获 换句话说,不支持,您无法在模拟器中访问或预览摄像头。