Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Detecting camera hardware

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 364
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: