We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

ScanUtil

class info
com.huawei.hms.hmsscankit.ScanUtil
Barcode scanning tool class, which is used to check permissions and start the barcode scanning page. This class provides the Default View and Bitmap modes for barcode scanning and a QR code generation API.

Constant Summary

TypeNameDesc
intSUCCESSThe code scanning view can be started.
intERROR_NO_CAMERA_PERMISSIONNo camera permission.
intERROR_NO_READ_PERMISSIONNo read permission.
StringRESULTDefines the result key.

Public Method Summary

Constants

Constant
public static final int SUCCESS
The code scanner view can be started.
Constant Value: 0
Constant
public static final int ERROR_NO_CAMERA_PERMISSION
No camera permission.
Constant Value: 1
Constant
public static final int ERROR_NO_READ_PERMISSION
No read permission.
Constant Value: 2
Constant
public static final String RESULT

Defines the result key.

Constant Value: SCAN_RESULT

Public Methods

Method
public static int startScan(android.app.Activity activity, int requestCode, HmsScanAnalyzerOptions option)
Checks the camera and storage permissions required for scanning. If the permissions are available, start the code scanning view provided by HUAWEI Scan Kit. If the permissions are unavailable, stay on the existing page.

Parameters

Parameter nameParameter desc
activityA scanning request activity.
requestCodeA scanning request code, which is used to check whether the activity is returned by the code scanning view.
optionBarcode scanning format option.

Return

Typedesc
intScanning request result status. The values SUCCESS, ERROR_NO_CAMERA_PERMISSION, and ERROR_NO_READ_PERMISSION indicate a successful request, no camera permission, and no storage permission, respectively.
Method
public static HmsScan[] decodeWithBitmap(android.content.Context context, android.graphics.Bitmap bitmap, HmsScanAnalyzerOptions format)
Bitmap decoding API.

Parameters

Parameter nameParameter desc
contextRequest context, which is generally the activity object that is being called, for example MainActivity.this.
bitmapImage to be decoded. For optimal effect, it is recommended that the image resolution range from 960px × 540px to 1920px × 1080px, with a maximum image size of 50 MB.
formatSpecified barcode scanning format.

Return

Typedesc
HmsScan[]Image decoding result.

public static android.graphics.Bitmap buildBitmap(String content, int type, int width, int height, HmsBuildBitmapOption options) throw WriterException

Generates 1D or 2D barcodes.

Parameters

Generated QR code image.Typedesc
contentQR code content.
typeBarcode format.
widthWidth of a QR code to be generated.
heightHeight of a QR code to be generated.
optionsBarcode generation option.

Return

Typedesc
android.graphics.Bitmap

Barcode.

Throws

Typedesc
WriterException

Barcode generation exception.

Search
Enter a keyword.