Code to check Camera exists or not in Android Device


PackageManager pm = this.getPackageManager();

        if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            System.out.println("---------has camera------");
                    }else{
            System.out.println("---------has no camera------");
                    }


-------------------------------------------------------

//It would be safer to use the constant PackageManager.FEATURE_CAMERA_FRONT
        //but since it is not defined for Android 2.2, I substituted the literal value
        frontCam = pm.hasSystemFeature("android.hardware.camera.front");
        System.out.println("frontCam"+frontCam);
        rearCam = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
        System.out.println("rearCam"+rearCam);
        if(frontCam || rearCam){
            camera.setVisibility(View.VISIBLE);
        }else{
            camera.setVisibility(View.GONE);
        }

Comments

Popular posts from this blog

Custom Dialog with no title and full screen in Android

Best working code to set Date limits on Date Picker Dialog,in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard