我正在尝试使用相机,但它无法启动。 hw.camera.back:Webcam()hw.camera.front:webcam()不知道还有什么要添加,因为我无法剪切和粘贴细节。
我得到的错误很遗憾,相机已停止。
我的代码如下,但它不是我的代码。当我尝试使用相机而不使用任何编程时,我得到相同的错误。
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);
在LogCat我有以下内容。我在LogCat中看到的一个我不明白的错误是电子邮件,我没有使用,我甚至不知道如何打开或关闭它。 D / ExchangeService(617):!!!未找到电子邮件申请;阻止自己
03-05 19:39:12.716: I/Choreographer(409): Skipped 90 frames! The application may be doing too much work on its main thread.
03-05 19:39:12.736: D/dalvikvm(818): GC_FOR_ALLOC freed 20K, 7% free 3675K/3936K, paused 59ms, total 66ms
03-05 19:39:12.875: D/dalvikvm(818): GC_FOR_ALLOC freed 5K, 7% free 4013K/4276K, paused 61ms, total 64ms
03-05 19:39:13.056: D/Camera(818): app passed NULL surface
03-05 19:39:13.076: V/EmulatedCamera_Camera(40): getCameraInfo
03-05 19:39:13.076: V/EmulatedCamera_BaseCamera(40): getCameraInfo
03-05 19:39:13.203: D/dalvikvm(818): GC_CONCURRENT freed 73K, 5% free 4429K/4656K, paused 12ms+55ms, total 197ms
03-05 19:39:13.203: V/camera(818): Preview size is 640x480
03-05 19:39:13.243: V/EmulatedCamera_Camera(40): setParameters
03-05 19:39:13.263: V/camera(818): startPreview
03-05 19:39:13.263: V/EmulatedCamera_Preview(40): setPreviewWindow: current: 0x0 -> new: 0x0
03-05 19:39:13.263: V/EmulatedCamera_Camera(40): doStartPreview
03-05 19:39:13.263: V/EmulatedCamera_Preview(40): startPreview
03-05 19:39:13.263: D/EmulatedCamera_Camera(40): Starting camera: 640x480 -> NV21(yuv420sp)
03-05 19:39:13.263: V/EmulatedCamera_QemuDevice(40): startDevice
03-05 19:39:13.276: V/EmulatedCamera_Device(40): commonStartDevice: Allocated 0x41c42008 460800 bytes for 307200 pixels in NV21[640x480] frame
03-05 19:39:15.273: D/dalvikvm(818): GC_FOR_ALLOC freed 49K, 4% free 4605K/4776K, paused 44ms, total 46ms
03-05 19:39:15.293: I/dalvikvm-heap(818): Grow heap (frag case) to 5.684MB for 1127536-byte allocation
03-05 19:39:15.293: E/EmulatedCamera_QemuClient(40): queryStart: Query failed: Cannot start the camera
03-05 19:39:15.313: E/EmulatedCamera_QemuDevice(40): startDevice: Unable to start device 'AndroidEmulatorVC0' for NV21[640x480] frames
03-05 19:39:15.313: V/EmulatedCamera_Preview(40): stopPreview
03-05 19:39:15.378: D/dalvikvm(818): GC_FOR_ALLOC freed 1K, 3% free 5704K/5880K, paused 85ms, total 85ms
03-05 19:39:15.383: V/EmulatedCamera_CallbackNotifier(40): disableMessage: msg_type = 0x10
03-05 19:39:15.383: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_PREVIEW_FRAME
03-05 19:39:15.383: V/EmulatedCamera_CallbackNotifier(40): **** Currently enabled messages:
03-05 19:39:15.383: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_ERROR
03-05 19:39:15.383: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_FOCUS
03-05 19:39:15.383: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_ZOOM
03-05 19:39:15.383: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_PREVIEW_METADATA
03-05 19:39:15.393: V/EmulatedCamera_Camera(40): doStopPreview
03-05 19:39:15.393: V/EmulatedCamera_CallbackNotifier(40): disableMessage: msg_type = 0x10
03-05 19:39:15.393: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_PREVIEW_FRAME
03-05 19:39:15.393: V/EmulatedCamera_CallbackNotifier(40): **** Currently enabled messages:
03-05 19:39:15.393: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_ERROR
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_FOCUS
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_ZOOM
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_PREVIEW_METADATA
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): disableMessage: msg_type = 0xffff
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_ERROR
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_SHUTTER
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_FOCUS
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_ZOOM
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_PREVIEW_FRAME
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_VIDEO_FRAME
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_POSTVIEW_FRAME
03-05 19:39:15.403: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_RAW_IMAGE
03-05 19:39:15.413: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_COMPRESSED_IMAGE
03-05 19:39:15.413: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_RAW_IMAGE_NOTIFY
03-05 19:39:15.413: V/EmulatedCamera_CallbackNotifier(40): CAMERA_MSG_PREVIEW_METADATA
03-05 19:39:15.413: V/EmulatedCamera_CallbackNotifier(40): **** Currently enabled messages:
03-05 19:39:15.413: V/EmulatedCamera_Camera(40): doStopPreview
03-05 19:39:15.413: V/EmulatedCamera_Camera(40): cancelPicture
03-05 19:39:15.413: V/EmulatedCamera_Camera(40): releaseCamera
03-05 19:39:15.413: V/EmulatedCamera_Camera(40): doStopPreview
03-05 19:39:15.423: V/EmulatedCamera_QemuDevice(40): disconnectDevice
03-05 19:39:15.423: V/EmulatedCamera_QemuDevice(40): disconnectDevice: Disonnected from device 'AndroidEmulatorVC0'
03-05 19:39:15.423: I/CameraClient(40): Destroying camera 0
03-05 19:39:15.423: V/EmulatedCamera_Camera(40): closeCamera
03-05 19:39:15.423: V/EmulatedCamera_Camera(40): doStopPreview
03-05 19:39:15.443: W/dalvikvm(818): threadid=11: thread exiting with uncaught exception (group=0x40a71930)
03-05 19:39:15.483: E/AndroidRuntime(818): FATAL EXCEPTION: Thread-67
03-05 19:39:15.483: E/AndroidRuntime(818): java.lang.RuntimeException: startPreview failed
03-05 19:39:15.483: E/AndroidRuntime(818): at com.android.camera.Camera.startPreview(Camera.java:1867)
03-05 19:39:15.483: E/AndroidRuntime(818): at com.android.camera.Camera.access$3100(Camera.java:87)
03-05 19:39:15.483: E/AndroidRuntime(818): at com.android.camera.Camera$5.run(Camera.java:1112)
03-05 19:39:15.483: E/AndroidRuntime(818): at java.lang.Thread.run(Thread.java:856)
03-05 19:39:15.483: E/AndroidRuntime(818): Caused by: java.lang.RuntimeException: startPreview failed
03-05 19:39:15.483: E/AndroidRuntime(818): at android.hardware.Camera.startPreview(Native Method)
03-05 19:39:15.483: E/AndroidRuntime(818): at com.android.camera.Camera.startPreview(Camera.java:1864)
03-05 19:39:15.483: E/AndroidRuntime(818): ... 3 more
03-05 19:39:15.513: W/AudioFlinger(40): session id 7 not found for pid 40
03-05 19:39:15.523: W/AudioFlinger(40): session id 8 not found for pid 40
03-05 19:39:15.553: W/ActivityManager(291): Force finishing activity com.android.camera/.Camera
03-05 19:39:15.772: D/dalvikvm(818): GC_CONCURRENT freed 25K, 3% free 5706K/5880K, paused 67ms+25ms, total 398ms
03-05 19:39:16.013: D/dalvikvm(291): GC_FOR_ALLOC freed 1373K, 27% free 8210K/11196K, paused 132ms, total 140ms
03-05 19:39:16.363: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
03-05 19:39:16.610: W/ActivityManager(291): Activity pause timeout for ActivityRecord{410f2198 u0 com.android.camera/.Camera}
03-05 19:39:16.813: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
03-05 19:39:16.873: W/EGL_emulation(409): eglSurfaceAttrib not implemented
03-05 19:39:29.058: W/ActivityManager(291): Activity destroy timeout for ActivityRecord{410f2198 u0 com.android.camera/.Camera}
03-05 19:39:54.407: D/ExchangeService(617): Received deviceId from Email app: null
03-05 19:39:54.407: D/ExchangeService(617): !!! deviceId unknown; stopping self and retrying
03-05 19:39:59.483: D/ExchangeService(617): !!! EAS ExchangeService, onCreate
03-05 19:39:59.483: D/ExchangeService(617): !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false
03-05 19:39:59.543: D/ExchangeService(617): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false
03-05 19:39:59.593: W/ActivityManager(291): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
03-05 19:39:59.593: D/ExchangeService(617): !!! Email application not found; stopping self
03-05 19:39:59.643: W/ActivityManager(291): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
03-05 19:39:59.663: E/ActivityThread(617): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d43240 that was originally bound here
03-05 19:39:59.663: E/ActivityThread(617): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d43240 that was originally bound here
03-05 19:39:59.663: E/ActivityThread(617): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
03-05 19:39:59.663: E/ActivityThread(617): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
03-05 19:39:59.663: E/ActivityThread(617): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
我刚刚在我的物理Samsung Galaxy Nexus running 4.2.2
上测试过这个并且运行得很好。 (原来我以为我只有4.2但我测试过4.2.2)
我还测试了在macbook pro上完美运行的模拟器上运行。我正在使用模拟器Target:"Google APIs (Google Inc) - API Level 17 (4.2.2)"
。
您必须确保AndroidManifest.xml中具有以下权限。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
这允许使用相机,自动对焦和写入存储
这是启动相机的代码
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent);
“111”可以替换为您使用的任何常量来识别结果回调函数中的活动。
1)如果你已经拥有权限我建议你进入Android Virtual Device Manager
并从头开始创建一个新的AVD
。
SD卡大小= 200 MB。并尝试使用和不使用,使用主机GPU。
2)接下来检查您的网络摄像头。您确定您使用的机器有网络摄像头及其功能吗?当然,如果网络摄像头不工作或没有安装,这将破坏事情。此外,您的机器上的驱动程序可能会出现AVD问题。否则,您可以尝试使用“仿真”选项,它基本上只显示测试/运动图像。
如果所有这些仍然有问题,那么它必须是你拥有这个intent startActivity
的代码。您应该尝试启动一个新的干净项目,将代码放在那里开始活动,修改我展示的AndroidManifest.xml as
并从那里开始。你也可以尝试在另一台机器上运行,因为机器上可能有网络摄像头(如果它有一个,有冲突的驱动程序)。我在macbook pro上测试并且100%工作
我希望能帮助你