Listing 19.12 - Possible Errata


#1

In regards to Listing 19.12 Checking for a camera (CrimeFragment.java):

PackageManager pm = getActivity().getPackageManager(); boolean hasACamera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT) || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA) || (Build.VERSION.SDK_INT>=Build.VERSION_CODES.GINGERBREAD && Camera.getNumberOfCameras()>0); if(!hasACamera) { mPhotoButton.setEnabled(false); }

The logic of the statement to check the camera version doesn’t seem right to me. In the text, you say that some emulators will return true if there is no camera available. If that’s the case, adding (Build.VERSION.SDK_INT>=Build.VERSION_CODES.GINGERBREAD && Camera.getNumberOfCameras()>0) to the Logical OR statement won’t fix this because for a logical OR statement, only one part of the statement has to be true for the whole statement to come back true.