diff --git a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java index 430fd746..3a0a07b5 100644 --- a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java +++ b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java @@ -19,6 +19,7 @@ import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.content.Context; +import android.content.pm.PackageManager; import android.graphics.ImageFormat; import android.graphics.SurfaceTexture; import android.hardware.Camera; @@ -53,7 +54,7 @@ /** * Manages the camera in conjunction with an underlying - * {@link com.google.android.gms.vision.Detector}. This receives preview frames from the camera at + * {@link Detector}. This receives preview frames from the camera at * a specified rate, sending those frames to the detector as fast as it is able to process those * frames. *
@@ -92,23 +93,23 @@ public class CameraSource { private static final float ASPECT_RATIO_TOLERANCE = 0.01f; @StringDef({ - Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, - Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, - Camera.Parameters.FOCUS_MODE_AUTO, - Camera.Parameters.FOCUS_MODE_EDOF, - Camera.Parameters.FOCUS_MODE_FIXED, - Camera.Parameters.FOCUS_MODE_INFINITY, - Camera.Parameters.FOCUS_MODE_MACRO + Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, + Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, + Camera.Parameters.FOCUS_MODE_AUTO, + Camera.Parameters.FOCUS_MODE_EDOF, + Camera.Parameters.FOCUS_MODE_FIXED, + Camera.Parameters.FOCUS_MODE_INFINITY, + Camera.Parameters.FOCUS_MODE_MACRO }) @Retention(RetentionPolicy.SOURCE) private @interface FocusMode {} @StringDef({ - Camera.Parameters.FLASH_MODE_ON, - Camera.Parameters.FLASH_MODE_OFF, - Camera.Parameters.FLASH_MODE_AUTO, - Camera.Parameters.FLASH_MODE_RED_EYE, - Camera.Parameters.FLASH_MODE_TORCH + Camera.Parameters.FLASH_MODE_ON, + Camera.Parameters.FLASH_MODE_OFF, + Camera.Parameters.FLASH_MODE_AUTO, + Camera.Parameters.FLASH_MODE_RED_EYE, + Camera.Parameters.FLASH_MODE_TORCH }) @Retention(RetentionPolicy.SOURCE) private @interface FlashMode {} @@ -740,6 +741,9 @@ public void onAutoFocusMoving(boolean start, Camera camera) { */ @SuppressLint("InlinedApi") private Camera createCamera() { + if (!isCameraHardware()) { + throw new RuntimeException("This device does not support camera."); + } int requestedCameraId = getIdForRequestedCamera(mFacing); if (requestedCameraId == -1) { throw new RuntimeException("Could not find requested camera."); @@ -814,6 +818,18 @@ private Camera createCamera() { return camera; } + /** + * Check the device supports camera + * + */ + private boolean isCameraHardware() { + if (mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){ + return true; + } else { + return false; + } + } + /** * Gets the id for the camera specified by the direction it is facing. Returns -1 if no such * camera was found. @@ -876,8 +892,8 @@ private static class SizePair { private Size mPreview; private Size mPicture; - public SizePair(android.hardware.Camera.Size previewSize, - android.hardware.Camera.Size pictureSize) { + public SizePair(Camera.Size previewSize, + Camera.Size pictureSize) { mPreview = new Size(previewSize.width, previewSize.height); if (pictureSize != null) { mPicture = new Size(pictureSize.width, pictureSize.height); @@ -905,18 +921,18 @@ public Size pictureSize() { */ private static List