Check if device has a camera?
Solution 1:
This is what I'm using
import android.content.pm.PackageManager;
PackageManager pm = context.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
}
All sorts of other fun things to test for are available too - the compass, is location available, is there a front facing camera: http://developer.android.com/reference/android/content/pm/PackageManager.html
Solution 2:
To find out how many cameras are available on your device, you can call:
import android.hardware.Camera;
int numCameras = Camera.getNumberOfCameras();
if (numCameras > 0) {
hasCamera = true;
}
Camera.getNumberOfCameras() is static, so it doesn't require actually connecting to a camera. This works since API 9.
Edit:
With the newer camera2 API, you can also call CameraManager.getCameraIdList(), which gives a list of the all the valid camera IDs, instead of just the count.