If we don't specify we require camera using manifest declaration, so we can check it at runtime that the camera is available or not.
To do this task, we have PackageManager class.
PackageManager has hasSystemFeature() method to check it, we just need to give PackageManager.FEATURE_CAMERA property to this method
We can also know the number of cameras available on a device by using Camera.getNumberOfCameras().
Below is the code
if (!checkCameraHardware(this)) {
showToast("This device has no camera");
return;
}
/** Check if this device has a camera */
private boolean checkCameraHardware(Context context) {
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
0 Comment(s)