Check if device has a camera?
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
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.
you should use this to find camera in your device
public static boolean isCameraAvailable(Context context) {
return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
}