Parsing Barcodes

The HmsScan object is returned by Scan Kit, which contains the barcode position in the input image, original data of the barcode, barcode format, structured data, and zoom ratio.

Call Mode

Return Object

Contained Content

Default View Mode

HmsScan

Original value of a barcode (obtained by getOriginalValue()).

Barcode format (obtained by getScanType()).

Structured data (obtained by getScanTypeForm()).

Barcode position in an image (obtained by getBorderRect()).

Customized View Mode

HmsScan

Original value of a barcode (obtained by getOriginalValue()).

Barcode format (obtained by getScanType()).

Structured data (obtained by getScanTypeForm()).

Barcode position in an image (obtained by getBorderRect()).

Bitmap Mode

HmsScan

Original value of a barcode (obtained by getOriginalValue()).

Barcode format (obtained by getScanType()).

Structured data (obtained by getScanTypeForm()).

Barcode position in an image (obtained by getBorderRect()).

Zoom ratio (obtained by setZoomValue(), which is contained only when photoMode is set to false).

HmsScanResult

Status code (obtained by getState())

Barcode scanning result (obtained by getHmsScans())

Multiprocessor Mode

HmsScan

Original value of a barcode (obtained by getOriginalValue()).

Barcode format (obtained by getScanType()).

Structured data (obtained by getScanTypeForm()).

Barcode position in an image (obtained by getBorderRect()).

  • You need to adjust the camera focal length based on the value of zoomValue. For details, please refer to Scanning Barcodes Using the Camera.
  • If you use the decode API of the Bitmap mode and need barcode parsing, set setParseResult() of HmsScanFrameOptions.Creator to true.
  • Structured data is valid information extracted from 1D and 2D barcodes encoded in a specific format. Scan Kit supports extracting valid information from Wi-Fi, EMAIL, PHONE, ISBN, PRODUCT, SMS, TEXT, URL, CONTACT INFO, GEO, CALENDAR EVENT, and DRIVER LICENSE barcodes, and returns the information to you. This helps you quickly build services. For details, please refer to HmsScan.

    The following table shows QR code images.

    QR Code

    Data Type Returned by Scan Kit

    Method for Obtaining the Data

    Data Obtained by the App

    Original value of a barcode

    getOriginalValue()

    smsto:18300000000:Hello World!

    Mobile number of an SMS message

    getDestPhoneNumber()

    18300000000

    SMS message content

    getSmsContent()

    Hello World!

    Original value of a barcode

    getOriginalValue()

    WIFI:S:WIFI_123;T:WPA;P:12345678;;

    Wi-Fi SSID

    getSsidNumber()

    WIFI_123

    Wi-Fi password

    getPassword()

    12345678

    Wi-Fi encryption type

    getCipherMode()

    WPA

    For example, if your app needs to obtain structured data related to SMS or Wi-Fi, please refer to the following code:
    Java
    Kotlin
    public void parseResult(HmsScan result) {
        if (result.getScanTypeForm() ==  HmsScan.SMS_FORM) {        
            // Parse the data into structured SMS data.
            HmsScan.SmsContent smsContent = result.getSmsContent();        
            String content = smsContent.getMsgContent();        
            String phoneNumber = smsContent.getDestPhoneNumber();    
        } else if (result.getScanTypeForm() == HmsScan.WIFI_CONNECT_INFO_FORM){        
            // Parse the data into structured Wi-Fi data.
            HmsScan.WiFiConnectionInfo wifiConnectionInfo = result.getWiFiConnectionInfo();        
            String password = wifiConnectionInfo.getPassword();        
            String ssidNumber = wifiConnectionInfo.getSsidNumber();        
            int cipherMode = wifiConnectionInfo.getCipherMode();    
        }
    }
    public fun parseResult(result:HmsScan) {
        if (result.getScanTypeForm() ==  HmsScan.SMS_FORM) {        
            // Parse the data into structured SMS data.
            val smsContent = result.getSmsContent()
            val content = smsContent.getMsgContent()
            val phoneNumber = smsContent.getDestPhoneNumber()
        } else if (result.getScanTypeForm() == HmsScan.WIFI_CONNECT_INFO_FORM){        
            // Parse the data into structured Wi-Fi data.
            val wifiConnectionInfo = result.getWiFiConnectionInfo()
            val password = wifiConnectionInfo.getPassword()
            val ssidNumber = wifiConnectionInfo.getSsidNumber()
            val cipherMode = wifiConnectionInfo.getCipherMode()
        }
    }
搜索
请输入您想要搜索的关键词