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
Example
- 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);
- ..
- }
- }
- }
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:
- @interface QRCodeScannerSDK : NSObject
- + (UIViewController * _Nullable)getQRCodeScannerSDKViewControllerWithDelegate:
- (id<QRCodeScannerSDKDelegate>)delegate
- vibrate:(BOOL)vibrate
- codeType:(int)codeType
- image:(UIImage *_Nullable)image
- error:(NSError **_Nullable)error;
- + (UIViewController * _Nullable)getQRCodeScannerSDKViewControllerWithDelegate:
- (id<QRCodeScannerSDKDelegate>)delegate
- vibrate:(BOOL)vibrate
- codeType:(int)codeType
- image:(UIImage *_Nullable)image
- scannerOverlay:(BOOL)scannerOverlay
- scannerOverlayColor:(UIColor *_Nullable)color
- error:(NSError **_Nullable)error;
- + (const NSString *)version;
- @end
Swift:
- public class QRCodeScannerSDK {
- public static func getQRCodeScannerSDKViewController(delegate: ScannerDelegate, vibrate: Bool, codeType: CodeType, image: UIImage?) throws -> UIViewController
- public static func getQRCodeScannerSDKViewController(delegate: ScannerDelegate, vibrate: Bool, codeType: CodeType, image: UIImage?, scannerOverlay: Bool, scannerOverlayColor: UIColor?) throws -> UIViewController
- public static var version: String
- }
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
Name | Value | Description |
---|---|---|
QRCodeScannerSDKConstants_IMAGE_MAX_SIZE | 2048 | Indicates the maximum width and height of a decoded image, in pixels. |