Functions of the Image Scanner SDK

Prev Next

Android

The Android API contains a method to decode and view the results of the static images in the Image Scanner SDK.

Bitmap Decoding Method

The following method decodes an image containing a Cronto image or QR code from a bitmap:

public static QRCodeScannerSDK.DecodingResultData decodeBitmap(androidx.graphics.Bitmap, int codeType) throws QRCodeScannerSDKException, LinkageError

The bitmap must be in ARGB_8888 format.

Image Decoding Method

The following method decodes the QR code in the image once it is detected:

public static QRCodeScannerSDK.DecodingResultData decodeImage(androidx.camera.core.ImageProxy image, int codeType) throws QRCodeScannerSDKException, LinkageError

Obtain Decoding Results

After decoding the QR code in the image, the QRCodeScannerSDKDecodingResultData obtains the results of the scan with the following methods:

public int getScannedImageFormat()

public String getScannedImageData()

Functions for Android [Deprecated]

The Android API consists of the QRCodeScannerSDKActivity class, which manages the behavior of the Image Scanner SDK.

The Android API returns a result code to indicate if a scan has been successful.

Display the scan result [Deprecated]

When a code is flashed, the QRcodeScannerSDKActivity class ends the scan process, and the activity is closed with the following code:

resultCode == RESULT_OK

The scan result will be transmitted with the OUTPUT_RESULT key.

Cancel the scan process [Deprecated]

When the back button is pressed, the QRCodeScannerSDKActivity instance is closed with the following code:

resultCode == RESULT_CANCELED

Exception [Deprecated]

If an error occurs, the caught exception is converted to a QRCodeScannerSDKException object. The QRCodeScannerSDKActivity ends the process and returns the following code:

resultCode == RESULT_ERROR

The result of the scan will be transmitted with the OUTPUT_EXCEPTION key.

QRCodeScannerSDKConstants [Deprecated]

The QRCodeScannerSDKConstants class contains the constants. The following table lists the available constants and parameters.

Properties

QRCodeScannerSDKConstants Properties for Android

Property Name

Data Type

Description

Android Extra Parameters

EXTRA_VIBRATE

Boolean

Indicates whether the device must vibrate when a QR code is scanned.

Key value: extra_vibrate

Default value: true

EXTRA_CODE_TYPE

int

Indicates which type of code can be parsed.

Key value: extra_code_type

Possible values are:

  • QRCodeScannerSDKConstants.QR_CODE

  • QRCodeScannerSDKConstants.CRONTO_CODE

  • QRCodeScannerSDKConstants.QR_CODE + QRCodeScannerSDKConstants.CRONTO_CODE

Default value: QRCodeScannerSDKConstants.QR_CODE + QRCodeScannerSDKConstants.CRONTO_CODE

QR_CODE

int

Indicates that the Image Scanner SDK must parse the image to search QR codes.

Key value: 0x01

EXTRA_SCANNER_OVERLAY

Boolean

Indicates that a scanner overlay will be displayed in scan view.

Key value: extra_scanner_overlay

Default value: false

EXTRA_SCANNER_OVERLAY_COLOR

int

Indicates the color that will be applied in the scanner overlay.

Key value: extra_scanner_overlay_color

Default value: 0x99000000

CRONTO_CODE

int

Indicates that the Image Scanner SDK must parse the image to search Cronto images.

Key value: 0x02

Android Return Parameters

OUTPUT_RESULT

String

Result of the scan.

Key value: output_result

OUTPUT_EXCEPTION

Exception

Caught exception.

Key value: output_exception

OUTPUT_CODE_TYPE

int

Code type result.

Key value: output_code_type

Possible values are:

  • QR_CODE

  • CRONTO_CODE

RESULT_ERROR

int

Indicates whether an exception has been thrown during the scanning process.

Key value: RESULT_FIRST_USER + 1

Example [Deprecated]

public void OnScanClicked(View v)
{
  ..
  // We want a vibration feedback after scanning
  // Note that the vibration feedback is activated by default
  intent.putExtra(QRCodeScannerSDKConstants.EXTRA_VIBRATE, true);
 
  // Indicate which sort of image we want to scan
  intent.putExtra(QRCodeScannerSDKConstants.EXTRA_CODE_TYPE, QRCodeScannerSDKConstants.QR_CODE +  QRCodeScannerSDKConstants.CRONTO_CODE);
 
  // Launch Image Scanner activity
  startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
  switch (resultCode)
  {
    case RESULT_OK:
      ..
      String result = data.getStringExtra (QRCodeScannerSDKConstants.OUTPUT_RESULT);
      int codeType = data.getIntExtra (QRCodeScannerSDKConstants.OUTPUT_CODE_TYPE, 0);
 
      // Convert the result
      if (codeType == QRCodeScannerSDKConstants.CRONTO_CODE)
      {
        // we have scan a cronto code => convert the hexa string to string
        byte[] tmp = hexaToBytes(result);
        ..
      }
      else if (codeType == QRCodeScannerSDKConstants.QR_CODE)
      {
        // we have scanned a QR code => display directly the result
        resultTextView.setText(result);
        ..
      }
  }
}

Known issue with Samsung Galaxy A23

Due to a known issue with the camera on Samsung Galaxy A23, Cronto codes are not decoded properly with the default resolution. The solution to this issue is to increase the resolution using the following code snippet:

var imageAnalysisBuilder = ImageAnalysis.Builder().setTargetRotation(rotation)
// Set Resolution property only for Samsung Galaxy A23 model
if(Build.MANUFACTURER.equals("Samsung", true) && Build.MODEL.contains("A23")) {
imageAnalysisBuilder.setTargetResolution(Size(1080, 1920))
}
imageAnalysisBuilder.build().setAnalyzer(cameraExecutor, QrCodeAnalyzer())

iOS

On iOS, the SDK supports the following primary use cases:

  • Scan and decode a QR code or Cronto image from a single image with the decodeImage method

  • Real-time decoding of QR codes and Cronto images by integrating the SDK with an AVCaptureSession; this is enabled with the configureAndBindSession method.