0

我正在尝试使用相机,但它无法启动。hw.camera.back: Webcam() hw.camera.front: webcam() 不确定还要添加什么,因为我无法剪切和粘贴详细信息。

我得到的错误是不幸的,相机已停止。

我的代码如下,但它不是我的代码。当我尝试在不使用任何编程的情况下使用相机时,我得到了同样的错误。

Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(takePictureIntent, actionCode);

在 LogCat 我有以下内容。我在 LogCat 中看到的一个我不理解的错误与我没有使用的电子邮件有关,我什至不知道如何打开或关闭它。D/交换服务(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)
4

1 回答 1

0

我刚刚在我的身体上对此进行了测试,Samsung Galaxy Nexus running 4.2.2并且运行良好。(最初我以为我只有 4.2,但我测试了 4.2.2)

我还测试了在 macbook pro 上完美运行的模拟器上运行。我正在使用模拟器目标:"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

  • 设备 = Galaxy Nexus
  • 目标 = Google API (Google Inc) - API 级别 17 (4.2.2)
  • 硬件键盘存在
  • 前置摄像头 - 网络摄像头
  • 后置摄像头 - 网络摄像头

SD 卡大小 = 200 MB。并尝试使用和不使用主机 GPU。

2)接下来是检查您的网络摄像头。您确定您使用的机器具有网络摄像头及其功能吗?当然,如果网络摄像头不工作或未安装,这会破坏一切。此外,您机器上的驱动程序可能与 AVD 存在问题。否则,您可以尝试对两者都使用“模拟”选项,它基本上只显示测试/移动图像。

如果这一切仍然有问题,那么它一定是你的代码有问题intent startActivity。您应该尝试开始一个新的干净项目,将代码放在那里以开始活动,修改AndroidManifest.xml as我展示的内容并从那里开始。您也可以尝试在另一台机器上运行,因为可能是您机器上的网络摄像头(如果有,驱动程序冲突)。我在 macbook pro 上测试过 100%

我希望这可以帮助你

于 2013-03-05T22:56:23.127 回答