- 04 Dec 2024
- 4 Minutes to read
- DarkLight
- PDF
Functions of the Image Scanner SDK
- Updated on 04 Dec 2024
- 4 Minutes to read
- DarkLight
- PDF
Android
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 [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:
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:
|
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
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:
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:
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:
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:
Swift:
func qrCodeScannerSDKControllerDidCancel(_ controller: UIViewController)
Exception
When an exception is thrown during the scan process, the callback threwException is called:
Swift:
func qrCodeScannerSDKController(_ controller: UIViewController, didReceive error: ScannerError)
Example
A sample application Swift is 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. |