Class IntentIntegrator


  • public class IntentIntegrator
    extends Object
    • Constructor Detail

      • IntentIntegrator

        public IntentIntegrator​(Activity activity)
    • Method Detail

      • getDefaultCaptureActivity

        protected Class<?> getDefaultCaptureActivity()
      • getCaptureActivity

        public Class<?> getCaptureActivity()
      • setCaptureActivity

        public IntentIntegrator setCaptureActivity​(Class<?> captureActivity)
        Set the Activity class to use. It can be any activity, but should handle the intent extras as used here.
        Parameters:
        captureActivity - the class
      • setRequestCode

        public IntentIntegrator setRequestCode​(int requestCode)
        Change the request code that is used for the Intent. If it is changed, it is the caller's responsibility to check the request code from the result intent.
        Parameters:
        requestCode - the new request code
        Returns:
        this
      • getMoreExtras

        public Map<String,​?> getMoreExtras()
      • setPrompt

        public final IntentIntegrator setPrompt​(String prompt)
        Set a prompt to display on the capture screen, instead of using the default.
        Parameters:
        prompt - the prompt to display
      • setOrientationLocked

        public IntentIntegrator setOrientationLocked​(boolean locked)
        By default, the orientation is locked. Set to false to not lock.
        Parameters:
        locked - true to lock orientation
      • setCameraId

        public IntentIntegrator setCameraId​(int cameraId)
        Use the specified camera ID.
        Parameters:
        cameraId - camera ID of the camera to use. A negative value means "no preference".
        Returns:
        this
      • setTorchEnabled

        public IntentIntegrator setTorchEnabled​(boolean enabled)
        Set to true to enable initial torch
        Parameters:
        enabled - true to enable initial torch
        Returns:
        this
      • setBeepEnabled

        public IntentIntegrator setBeepEnabled​(boolean enabled)
        Set to false to disable beep on scan.
        Parameters:
        enabled - false to disable beep
        Returns:
        this
      • setBarcodeImageEnabled

        public IntentIntegrator setBarcodeImageEnabled​(boolean enabled)
        Set to true to enable saving the barcode image and sending its path in the result Intent.
        Parameters:
        enabled - true to enable barcode image
        Returns:
        this
      • setDesiredBarcodeFormats

        public IntentIntegrator setDesiredBarcodeFormats​(Collection<String> desiredBarcodeFormats)
        Set the desired barcode formats to scan.
        Parameters:
        desiredBarcodeFormats - names of BarcodeFormats to scan for
        Returns:
        this
      • setDesiredBarcodeFormats

        public IntentIntegrator setDesiredBarcodeFormats​(String... desiredBarcodeFormats)
        Set the desired barcode formats to scan.
        Parameters:
        desiredBarcodeFormats - names of BarcodeFormats to scan for
        Returns:
        this
      • initiateScan

        public final void initiateScan()
        Initiates a scan for all known barcode types with the default camera.
      • setTimeout

        public IntentIntegrator setTimeout​(long timeout)
        Initiates a scan for all known barcode types with the default camera. And starts a timer to finish on timeout
        Returns:
        Activity.RESULT_CANCELED and true on parameter TIMEOUT.
      • createScanIntent

        public Intent createScanIntent()
        Create an scan intent with the specified options.
        Returns:
        the intent
      • initiateScan

        public final void initiateScan​(Collection<String> desiredBarcodeFormats)
        Initiates a scan, only for a certain set of barcode types, given as strings corresponding to their names in ZXing's BarcodeFormat class like "UPC_A". You can supply constants like PRODUCT_CODE_TYPES for example.
        Parameters:
        desiredBarcodeFormats - names of BarcodeFormats to scan for
      • startActivity

        protected void startActivity​(Intent intent)
      • parseActivityResult

        public static IntentResult parseActivityResult​(int requestCode,
                                                       int resultCode,
                                                       Intent intent)

        Call this from your Activity's Activity.onActivityResult(int, int, Intent) method.

        This checks that the requestCode is equal to the default REQUEST_CODE.

        Parameters:
        requestCode - request code from onActivityResult()
        resultCode - result code from onActivityResult()
        intent - Intent from onActivityResult()
        Returns:
        null if the event handled here was not related to this class, or else an IntentResult containing the result of the scan. If the user cancelled scanning, the fields will be null.
      • parseActivityResult

        public static IntentResult parseActivityResult​(int resultCode,
                                                       Intent intent)
        Parse activity result, without checking the request code.
        Parameters:
        resultCode - result code from onActivityResult()
        intent - Intent from onActivityResult()
        Returns:
        an IntentResult containing the result of the scan. If the user cancelled scanning, the fields will be null.