Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
| Class Info |
|---|
| public class ScanUtil Barcode scanning utility class, which is used to check permissions and start the barcode scanning screen. This class supports barcode scanning in Default View mode and Bitmap mode and provides an API for generating barcodes. |
| Qualifier and Type | Field and Description |
|---|---|
| static final int | The camera failed to be initialized. |
| static final int | No camera access permission. |
| static final int | The app does not have the read permission on the file directory. |
| static final String | Result key. |
| static final String | Result key, indicating the returned result. |
| static final int | No barcode is detected. |
| static final int | Barcode scanning screen started successfully. |
| Qualifier and Type | Method Name and Description |
|---|---|
| static Bitmap | buildBitmap(String content, int type, int width, int height, HmsBuildBitmapOption options) throws WriterException Generates a 1D or 2D barcode. |
| static Bitmap | compressBitmap(Context context, String path) Obtains the bitmap from a specific path, compresses the bitmap to a lower sampling rate, and then returns the compressed bitmap that meets the size requirements. |
| static HmsScanResult | decode(Context context, HmsScanFrame frame, HmsScanFrameOptions options) Decodes a scanned image that can contain either a single barcode or multiple barcodes. |
| static HmsScan[] | decodeWithBitmap(Context context, Bitmap bitmap, HmsScanAnalyzerOptions format) Decodes a scanned image in Bitmap mode. |
| static int | startScan(Activity activity, int requestCode, HmsScanAnalyzerOptions option) Scans barcodes in Default View mode. |
| static void | setOperationTrackingEnabled(boolean enabled) Enables the O&M capability. This capability is enabled by default. |
| Field |
|---|
| public static final int CAMERA_INIT_ERROR The camera failed to be initialized. For details, see Result Codes. |
| Field |
|---|
| public static final int ERROR_NO_CAMERA_PERMISSION No camera access permission. For details, see Result Codes. |
| Field |
|---|
| public static final int ERROR_NO_READ_PERMISSION The app does not have the read permission on the file directory. For details, see Result Codes. |
| Field |
|---|
| public static final String RESULT Result key. Constant value: SCAN_RESULT |
| Field |
|---|
| public static final String RESULT_CODE Result key, indicating the returned result. Constant value: SCAN_RESULT_CODE |
| Field |
|---|
| public static final int SCAN_NO_DETECTED No barcode is detected. Constant value: 4096 |
| Field |
|---|
| public static final int SUCCESS Barcode scanning screen started successfully. Constant value: 0 |
| Method |
|---|
| public static Bitmap buildBitmap(String content, int type, int width, int height, HmsBuildBitmapOption options) throws WriterException Generates a 1D or 2D barcode. |
Parameters
| Name | Description |
|---|---|
| content | Barcode content. For details about barcode generation configurations, please refer to Recommended Settings for Barcode Generation. |
| type | Barcode format. Currently, Scan Kit supports the following barcode formats: EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code 39, Code 93, Code 128, ITF-14, QR Code, DataMatrix, PDF417, and Aztec. For details, see Public Field Summary. |
| width | Width of a barcode to be generated. |
| height | Height of a barcode to be generated. |
| options | Barcode generation options. |
Throws
| Name | Description |
|---|---|
| Barcode generation exception. |
Returns
| Type | Description |
|---|---|
| Bitmap | Generated barcode. |
| Method |
|---|
| public static Bitmap compressBitmap(Context context, String path) Obtains the bitmap from a specific path, compresses the bitmap to a lower sampling rate, and then returns the compressed bitmap that meets the size requirements. |
Parameters
| Name | Description |
|---|---|
| context | Request context, which is generally the activity object that is being called, for example, MainActivity.this. |
| path | Bitmap path. |
Returns
| Type | Description |
|---|---|
| Bitmap | Compressed bitmap. |
| Method |
|---|
| public static HmsScanResult decode(Context context, HmsScanFrame frame, HmsScanFrameOptions options) Decodes a scanned image that can contain either a single barcode or multiple barcodes. |
Parameters
| Name | Description |
|---|---|
| context | App context. |
| frame | Image data of the barcode scanning request. The following formats are supported: NV21 and bitmap. |
| options | Scanning format options. |
Returns
| Type | Description |
|---|---|
| HmsScanResult | Result of the barcode scanning request.
|
| Method |
|---|
| public static HmsScan[] decodeWithBitmap(Context context, Bitmap bitmap, HmsScanAnalyzerOptions format) Decodes a scanned image in Bitmap mode. |
Parameters
| Name | Description |
|---|---|
| context | Request context, which is generally the activity object that is being called, for example, MainActivity.this. |
| bitmap | Image to be decoded. For a desired effect, it is recommended that the image dimensions range from 960 x 540 px to 1920 x 1080 px, with a maximum image size of 50 MB. |
| format | Specified barcode format. |
Returns
| Type | Description |
|---|---|
| HmsScan[] | Image decoding result. |
| Method |
|---|
| public static int startScan(Activity activity, int requestCode, HmsScanAnalyzerOptions option) Scans barcodes in Default View mode. Before the scanning, it checks whether your app has the camera access permission and the storage permission required for scanning. If so, the scanning screen defined by Scan Kit is displayed; otherwise, your app will exit the scanning screen. |
Parameters
| Name | Description |
|---|---|
| activity | Scanning request activity. |
| requestCode | Scanning request code, which is used to check whether the activity of the barcode scanning screen is returned. |
| option | Scanning format options. |
Returns
| Type | Description |
|---|---|
| int | Scanning request result. |
| Method |
|---|
| public static void setOperationTrackingEnabled(boolean enabled) Enables the O&M capability. This capability is enabled by default. |
Parameters
| Name | Description |
|---|---|
| enabled | Indicates whether to collect information for statistical analysis and user experience improvement.
|