public static Camera open()
Creates a new Camera object to access the first back-facingcamera on the device. If the device does not have a back-facingcamera, this returns null.
See Also
open(int)
而2.3中open函数是有参数的open(int cameraId),
public static Camera open (intcameraId)
Creates a new Camera object to access a particular hardwarecamera.
You must call release()
when you are done usingthe camera, otherwise it will remain locked and be unavailable toother applications.
Your application should only have one Camera object active at atime for a particular hardware camera.
Callbacks from other methods are delivered to the event loop ofthe thread which called open(). If this thread has no event loop,then callbacks are delivered to the main application event loop. Ifthere is no main application event loop, callbacks are notdelivered.
Caution: On some devices, this method may take a longtime to complete. It is best to call this method from a workerthread (possibly using AsyncTask
) to avoidblocking 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 thecamera is in use by another process). |
---|
为了验证是这个函数的问题,我在camera.open()函数进行出错处理
在2.3上运行,报错是NullPointer空指针错误,也打印出“open()方法有问题”这个语句,说明问题真的处在这个函数上,到底参数是多少呢,API上说cameraId的值在0到getNumberOfCameras()-1之间,试过0,也试过getNumberOfCamera-1,但是依旧报错,看来这个问题暂时还无法解决了。。。