在調試器中運行此我看到info.facing == 0。這意味着它是一個背面相機。相機模擬器「面對」行事奇怪
當我嘗試實例化Camrea對象時,我得到空值。
在仿真器上,我將設備設置爲禁用camrea禁用並啓用前置攝像頭。爲什麼該設備在沒有時會認爲存在背對背卡路里?
我正在使用Eclipse ADT。
這裏是我的方法。我從來沒有達到第二個循環。 getCamreaInstance返回空值爲c的c。
public static Camera getCameraInstance(){
Camera c = null;
CameraInfo info = new CameraInfo();
if (info.facing == CameraInfo.CAMERA_FACING_BACK){
//Calling Camera.open() throws an exception if the camera is already in use by another application, so we wrap it in a try block.
//Failing to check for exceptions if the camera is in use or does not exist will cause your application to be shut down by the system.
try {
c = Camera.open();
}
catch (Exception e){
// Camera is not available (in use or does not exist)
}
return c;
}
//we want the back facing, if we cant get that then we try and get the front facing
else if (info.facing == CameraInfo.CAMERA_FACING_FRONT){
c = Camera.open(Camera.getNumberOfCameras()-1); //i should test and see if -1 is a valid value in the case that a device has no camera
return c;
}
else{
//there are no cameras, so we need to account for that since 'c' will be null
return c;
}
}
請原諒我的無知。 java中的#有什麼作用? 也是getCameraInfo一個有效的方法與空參數?它看起來像在這裏的API文件,但不是在我的IDE ... http://developer.android.com/reference/android/hardware/Camera.CameraInfo.html#Camera.CameraInfo() –
對不起,'' #'只是表示方法的符號。這是一種靜態方法,不,沒有參數沒有選項。爲了保存輸入參數,我鏈接到方法的文檔,以便您可以自己查看。空構造函數顯示在文檔中,因爲根據定義,所有對象都有一個空的構造函數。儘管如此,它不會做任何事情。 – Geobits
很高興知道。謝謝你清理那個。 你是對的這個答案 –