Class CaptureManager


  • public class CaptureManager
    extends Object
    Manages barcode scanning for a CaptureActivity. This class may be used to have a custom Activity (e.g. with a customized look and feel, or a different superclass), but not the barcode scanning process itself. This is intended for an Activity that is dedicated to capturing a single barcode and returning it via setResult(). For other use cases, use DefaultBarcodeScannerView or BarcodeView directly. The following is managed by this class: - Orientation lock - InactivityTimer - BeepManager - Initializing from an Intent (via IntentIntegrator) - Setting the result and finishing the Activity when a barcode is scanned - Displaying camera errors
    • Method Detail

      • initializeFromIntent

        public void initializeFromIntent​(Intent intent,
                                         Bundle savedInstanceState)
        Perform initialization, according to preferences set in the intent.
        Parameters:
        intent - the intent containing the scanning preferences
        savedInstanceState - saved state, containing orientation lock
      • lockOrientation

        protected void lockOrientation()
        Lock display to current orientation.
      • decode

        public void decode()
        Start decoding.
      • onResume

        public void onResume()
        Call from Activity#onResume().
      • onRequestPermissionsResult

        public void onRequestPermissionsResult​(int requestCode,
                                               String[] permissions,
                                               int[] grantResults)
        Call from Activity#onRequestPermissionsResult
        Parameters:
        requestCode - The request code passed in ActivityCompat.requestPermissions(Activity, String[], int).
        permissions - The requested permissions.
        grantResults - The grant results for the corresponding permissions which is either PackageManager.PERMISSION_GRANTED or PackageManager.PERMISSION_DENIED. Never null.
      • onPause

        public void onPause()
        Call from Activity#onPause().
      • onDestroy

        public void onDestroy()
        Call from Activity#onDestroy().
      • onSaveInstanceState

        public void onSaveInstanceState​(Bundle outState)
        Call from Activity#onSaveInstanceState().
      • resultIntent

        public static Intent resultIntent​(BarcodeResult rawResult,
                                          String barcodeImagePath)
        Create a intent to return as the Activity result.
        Parameters:
        rawResult - the BarcodeResult, must not be null.
        barcodeImagePath - a path to an exported file of the Barcode Image, can be null.
        Returns:
        the Intent
      • closeAndFinish

        protected void closeAndFinish()
      • returnResultTimeout

        protected void returnResultTimeout()
      • returnResult

        protected void returnResult​(BarcodeResult rawResult)
      • displayFrameworkBugMessageAndExit

        protected void displayFrameworkBugMessageAndExit​(String message)
      • getCameraPermissionReqCode

        public static int getCameraPermissionReqCode()
      • setCameraPermissionReqCode

        public static void setCameraPermissionReqCode​(int cameraPermissionReqCode)
      • setShowMissingCameraPermissionDialog

        public void setShowMissingCameraPermissionDialog​(boolean visible)
        If set to true, shows the default error dialog if camera permission is missing.

        If set to false, instead the capture manager just finishes.

        In both cases, the activity result is set to Intents.Scan.MISSING_CAMERA_PERMISSION and cancelled

      • setShowMissingCameraPermissionDialog

        public void setShowMissingCameraPermissionDialog​(boolean visible,
                                                         String message)
        If set to true, shows the specified error dialog message if camera permission is missing.

        If set to false, instead the capture manager just finishes.

        In both cases, the activity result is set to Intents.Scan.MISSING_CAMERA_PERMISSION and cancelled