diff --git a/android/src/main/java/com/amolg/flutterbarcodescanner/BarcodeCaptureActivity.java b/android/src/main/java/com/amolg/flutterbarcodescanner/BarcodeCaptureActivity.java index b44216a1..2659cb70 100755 --- a/android/src/main/java/com/amolg/flutterbarcodescanner/BarcodeCaptureActivity.java +++ b/android/src/main/java/com/amolg/flutterbarcodescanner/BarcodeCaptureActivity.java @@ -111,33 +111,33 @@ public void onCreate(Bundle icicle) { String buttonText = ""; try { - buttonText = (String) getIntent().getStringExtra("cancelButtonText"); - } catch (Exception e) { - buttonText = "Cancel"; - Log.e("BCActivity:onCreate()", "onCreate: " + e.getLocalizedMessage()); - } + buttonText = (String) getIntent().getStringExtra("cancelButtonText"); + } catch (Exception e) { + buttonText = "Cancel"; + Log.e("BCActivity:onCreate()", "onCreate: " + e.getLocalizedMessage()); + } - Button btnBarcodeCaptureCancel = findViewById(R.id.btnBarcodeCaptureCancel); - btnBarcodeCaptureCancel.setText(buttonText); - btnBarcodeCaptureCancel.setOnClickListener(this); + Button btnBarcodeCaptureCancel = findViewById(R.id.btnBarcodeCaptureCancel); + btnBarcodeCaptureCancel.setText(buttonText); + btnBarcodeCaptureCancel.setOnClickListener(this); - imgViewBarcodeCaptureUseFlash = findViewById(R.id.imgViewBarcodeCaptureUseFlash); - imgViewBarcodeCaptureUseFlash.setOnClickListener(this); - imgViewBarcodeCaptureUseFlash.setVisibility(FlutterBarcodeScannerPlugin.isShowFlashIcon ? View.VISIBLE : View.GONE); + imgViewBarcodeCaptureUseFlash = findViewById(R.id.imgViewBarcodeCaptureUseFlash); + imgViewBarcodeCaptureUseFlash.setOnClickListener(this); + imgViewBarcodeCaptureUseFlash.setVisibility(FlutterBarcodeScannerPlugin.isShowFlashIcon ? View.VISIBLE : View.GONE); - imgViewSwitchCamera = findViewById(R.id.imgViewSwitchCamera); - imgViewSwitchCamera.setOnClickListener(this); + imgViewSwitchCamera = findViewById(R.id.imgViewSwitchCamera); + imgViewSwitchCamera.setOnClickListener(this); - mPreview = findViewById(R.id.preview); - mGraphicOverlay = findViewById(R.id.graphicOverlay); + mPreview = findViewById(R.id.preview); + mGraphicOverlay = findViewById(R.id.graphicOverlay); - // read parameters from the intent used to launch the activity. - boolean autoFocus = true; - boolean useFlash = false; + // read parameters from the intent used to launch the activity. + boolean autoFocus = true; + boolean useFlash = false; - // Check for the camera permission before accessing the camera. If the - // permission is not granted yet, request permission. - int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); + // Check for the camera permission before accessing the camera. If the + // permission is not granted yet, request permission. + int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash, CameraSource.CAMERA_FACING_BACK); } else { @@ -419,13 +419,30 @@ public void onClick(View v) { finish(); } else if (i == R.id.imgViewSwitchCamera) { int currentFacing = mCameraSource.getCameraFacing(); - boolean autoFocus = mCameraSource.getFocusMode() != null; - boolean useFlash = flashStatus == USE_FLASH.ON.ordinal(); - createCameraSource(autoFocus, useFlash, getInverseCameraFacing(currentFacing)); - startCameraSource(); + int inverseFacing = getInverseCameraFacing(currentFacing); + if (hasCamera(inverseFacing)) { + boolean autoFocus = mCameraSource.getFocusMode() != null; + boolean useFlash = flashStatus == USE_FLASH.ON.ordinal(); + createCameraSource(autoFocus, useFlash, inverseFacing); + startCameraSource(); + } } } + private boolean hasCamera(int cameraFacing) { + Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); + int numberOfCameras = Camera.getNumberOfCameras(); + + for (int i = 0; i < numberOfCameras; i++) { + Camera.getCameraInfo(i, cameraInfo); + if (cameraInfo.facing == cameraFacing) { + return true; + } + } + + return false; + } + private int getInverseCameraFacing(int cameraFacing) { if (cameraFacing == CameraSource.CAMERA_FACING_FRONT) { return CameraSource.CAMERA_FACING_BACK; diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh deleted file mode 100755 index 9e2cc398..00000000 --- a/example/ios/Flutter/flutter_export_environment.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -# This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Volumes/MyData/Flutter_SDK/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/admin/Desktop/FlutterBarcodeScanner/flutter_barcode_scanner/example" -export "FLUTTER_TARGET=lib/main.dart" -export "FLUTTER_BUILD_DIR=build" -export "SYMROOT=${SOURCE_ROOT}/../build/ios" -export "FLUTTER_BUILD_NAME=2.0.0.0" -export "FLUTTER_BUILD_NUMBER=2.0.0.0" -export "DART_OBFUSCATION=false" -export "TRACK_WIDGET_CREATION=false" -export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=.packages"