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

Image Decoding Method

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

public static QRCodeScannerSDKDecodingResultData decodeImage(Image 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

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

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

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

resultCode == RESULT_CANCELED

Exception

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

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

  1. public void OnScanClicked(View v)
  2. {
  3.   ..
  4.   // We want a vibration feedback after scanning
  5.   // Note that the vibration feedback is activated by default
  6.   intent.putExtra(QRCodeScannerSDKConstants.EXTRA_VIBRATE, true);
  7.  
  8.   // Indicate which sort of image we want to scan
  9.   intent.putExtra(QRCodeScannerSDKConstants.EXTRA_CODE_TYPE, QRCodeScannerSDKConstants.QR_CODE +  QRCodeScannerSDKConstants.CRONTO_CODE);
  10.  
  11.   // Launch Image Scanner activity
  12.   startActivityForResult(intent, 1);
  13. }
  14. @Override
  15. protected void onActivityResult(int requestCode, int resultCode, Intent data)
  16. {
  17.   switch (resultCode)
  18.   {
  19.     case RESULT_OK:
  20.       ..
  21.       String result = data.getStringExtra (QRCodeScannerSDKConstants.OUTPUT_RESULT);
  22.       int codeType = data.getIntExtra (QRCodeScannerSDKConstants.OUTPUT_CODE_TYPE, 0);
  23.  
  24.       // Convert the result
  25.       if (codeType == QRCodeScannerSDKConstants.CRONTO_CODE)
  26.       {
  27.         // we have scan a cronto code => convert the hexa string to string
  28.         byte[] tmp = hexaToBytes(result);
  29.         ..
  30.       }
  31.       else if (codeType == QRCodeScannerSDKConstants.QR_CODE)
  32.       {
  33.         // we have scanned a QR code => display directly the result
  34.         resultTextView.setText(result);
  35.         ..
  36.       }
  37.   }
  38. }

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

Image Decoding Method

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

In Objective-C:

+ (QRCodeScannerSDKDecodingResultData * _Nullable)decodeImage:(UIImage *)image ofType:(int)codeType error:(NSError ** _Nullable)error;

In Swift:

public static func decodeImage(_ image: UIImage, codeType: CodeType) throws -> QRCodeScannerSDKDecodingResultData

Obtain Decoding Results

After decoding the QR code in the image, the QRCodeScannerSDKDecodingResultData obtains the results of the scan. The result contains the following fields.

In Objective-C:

int codeType;

NSString *result;

In Swift:

var codeType: CodeType

var result: String

Functions for iOS

The main entry is a UIViewController returned by the SDK. The following API is available to obtain the instance:

Objective-C:

  1. @interface QRCodeScannerSDK : NSObject
  2. + (UIViewController * _Nullable)getQRCodeScannerSDKViewControllerWithDelegate:
  3. (id<QRCodeScannerSDKDelegate>)delegate
  4. vibrate:(BOOL)vibrate
  5. codeType:(int)codeType
  6. image:(UIImage *_Nullable)image
  7. error:(NSError **_Nullable)error;
  8. + (UIViewController * _Nullable)getQRCodeScannerSDKViewControllerWithDelegate:
  9. (id<QRCodeScannerSDKDelegate>)delegate
  10. vibrate:(BOOL)vibrate
  11. codeType:(int)codeType
  12. image:(UIImage *_Nullable)image
  13. scannerOverlay:(BOOL)scannerOverlay
  14. scannerOverlayColor:(UIColor *_Nullable)color
  15. error:(NSError **_Nullable)error;
  16. + (const NSString *)version;
  17. @end

Swift:

  1. public class QRCodeScannerSDK {
  2. public static func getQRCodeScannerSDKViewController(delegate: ScannerDelegate, vibrate: Bool, codeType: CodeType, image: UIImage?) throws -> UIViewController
  3. public static func getQRCodeScannerSDKViewController(delegate: ScannerDelegate, vibrate: Bool, codeType: CodeType, image: UIImage?, scannerOverlay: Bool, scannerOverlayColor: UIColor?) throws -> UIViewController
  4. public static var version: String
  5. }

Parameter details:

  • vibrate: input parameter. The phone will vibrate when a QR code or a Cronto image has been flashed, if the corresponding option is configured. This option is available when the vibrate input parameter is used.
  • codeType: input parameter. The Image Scanner SDK can scan either the content of the QR code or the Cronto image, or both. This option is available when the codeType input parameter is used. Possible values are:

Objective-C:

QRCodeScannerSDKConstants.QR_CODE

QRCodeScannerSDKConstants.CRONTO_CODE

QRCodeScannerSDKConstants.QR_CODE + QRCodeScannerSDKConstants.CRONTO_CODE

The default value enables scanning for all types.

Swift:

CodeType.qrCode

CodeType.crontoCode

CodeType.all

The default value enables scanning for all types.

  • image: to customize the icon for canceling the scan process.
  • delegate: protocol to manage the callbacks of the view controller instance returned by the SDK. It contains three methods to manage the QR code scanning process and must be implemented in your application.
  • scannerOverlay: if set to YES, a scanner overlay is added to the scan view. By default this overlay is disabled.
  • scannerOverlayColor: To customize the color of the overlay. If set to null, the default color (0x99000000) is used.

Display the scan result

This method is called when a code has been scanned, with the result of the scan as the input parameter:

Objective-C:

(void)qrCodeScannerSDKController:(QRCodeScannerSDKViewController*) controller didScanResult:(NSString *)result withCodeType:(int)codeType;

Swift:

func qrCodeScannerSDKController(_ controller: UIViewController, didScan result: String, codeType: CodeType)

Cancel the scan process

When the end user presses the relevant icon, qrCodeScannerSDKControllerDidCancel is called, which closes the image scanner:

Objective-C:

(void)qrCodeScannerSDKControllerDidCancel: (QRCodeScannerSDKViewController*)controller;

Swift:

func qrCodeScannerSDKControllerDidCancel(_ controller: UIViewController)

Exception

When an exception is thrown during the scan process, the callback threwException is called:

Objective-C:

(void)qrCodeScannerSDKController:(QRCodeScannerSDKViewController*) controller threwException:(QRCodeScannerSDKException *)exception;

Swift:

func qrCodeScannerSDKController(_ controller: UIViewController, didReceive error: ScannerError)

Example

Sample Applications in Objective-C and Swift are provided along with this package.

QRCodeScannerSDKConstants

The QRCodeScannerSDKConstants file contains the constant, fixed values for the Image Scanner SDK in iOS.

Properties

QRCodeScannerSDKConstants values for iOS
Name Value Description
QRCodeScannerSDKConstants_IMAGE_MAX_SIZE 2048 Indicates the maximum width and height of a decoded image, in pixels.