android camera :fail&n…

发布时间:2016-12-6 18:17:27 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"android camera :fail&n…",主要涉及到android camera :fail&n…方面的内容,对于android camera :fail&n…感兴趣的同学可以参考一下。

敲了一个android camera 的代码。运行后报:fail to connect to camera service的错误,无法解决,在网上搜索了一下,貌似大家都有这个问题,但是还是无法解决,首先,要在AndroidManifest.xml文件中 添加权限允许语句: ,这个是我忽略了的,本以为添加上去了就可以解决了,但是依旧是这个错误。后来在网上看到一个论坛的回复,他指出,在2.2上运行camera应用没有报 错,但是在2.3上运行就会报这个错误,抱着半信半疑的态度,试了一下,果然是这样的,他还指出,是camera.open()函数的问题。2.2版本中 camera.open()的open()函数是没有参数的 Camera android.hardware.Camera.open() public static Camera open () Since: API Level 1 Creates a new Camera object to access the first back-facing camera on the device. If the device does not have a back-facing camera, this returns null. See Also open(int) 而2.3中open函数是有参数的open(int cameraId),   Camera android.hardware.Camera.open(int cameraId) public static Camera open (int cameraId) Since: API Level 9 Creates a new Camera object to access a particular hardware camera. You must call release() when you are done using the camera, otherwise it will remain locked and be unavailable to other applications. Your application should only have one Camera object active at a time for a particular hardware camera. Callbacks from other methods are delivered to the event loop of the thread which called open(). If this thread has no event loop, then callbacks are delivered to the main application event loop. If there is no main application event loop, callbacks are not delivered. Caution: On some devices, this method may take a long time to complete. It is best to call this method from a worker thread (possibly using AsyncTask) to avoid blocking the main application UI thread. Parameters cameraId the hardware camera to access, between 0 and getNumberOfCameras()-1. Returns a new Camera object, connected, locked and ready for use. Throws RuntimeException if connection to the camera service fails (for example, if the camera is in use by another process). 为了验证是这个函数的问题,我在camera.open()函数进行出错处理  try{   mCamera = Camera.open(Camera.getNumberOfCameras()-1);   }   catch(RuntimeException e){    System.out.println("open()方法有问题");   } 在 2.3上运行,报错是nullpointer空指针错误,也打印出“open()方法有问题”这个语句,说明问题真的处在这个函数上,到底参数是多少 呢,API上说cameraId的值在0到getNumberOfCameras()-1之间,试过0,也试过getNumberOfCamera-1, 但是依旧报错,看来这个问题暂时还无法解决了。。。

上一篇:fmt标签国际化
下一篇:Android谁动了我的内存

相关文章

相关评论