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)