Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check if a device has camera in Android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 814
    Comment on it

    At times, we make apps which use camera feature but that app can also be used on non camera devices for other features. There we have to apply a check on using the camera feature, that is as follows:

    PackageManager packageManager = activity.getPackageManager();
    
        //checking if device has camera
        if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            //yes, perform the further camera code here.
            Toast.makeText(activity, "The device has camera.", Toast.LENGTH_SHORT).show();
        }else{
            //camera not found.
            Toast.makeText(activity, "The device has no camera.", Toast.LENGTH_SHORT).show();
        }
    

    PackageManager class used above can also be used to detect other features like wifi, bluetooth, flash, autofocus, gps, network etc.

 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: