Decades have passed since the invention and development of two-dimensional codes and barcodes. They are widely used in the era of digital economy because of their fast and convenient information reading characteristics. Scanning QR codes can identify health conditions, identify identity information, access website links, complete financial payments, etc., and has become an indispensable practical technology in life, so many apps are equipped with the "scan" function.
However, in the daily scanning process, we often encounter situations such as dark scanning environment, contamination and blurring of the QR code, etc., which make it difficult to identify the QR code. HMS Core unified code scanning service (Scan Kit) has made targeted recognition optimization for common complex code scanning scenarios (such as reflection, dark light, contamination, blur, and cylinder), and can also realize the detection and detection of long-distance codes or small codes. Automatically zoom in to improve the scanning success rate and user experience.
1. Scan code from a distance
Ordinary QR code scanners have a read-only distance of no more than 30 cm. However, long-distance code scanning often occurs in our lives, such as long-distance scanning code payment in parking lots, scanning code for sign-in in public, etc. The ordinary scanning code service is in At this time, it will be difficult to scan the code. The unified scanning code service, because of the addition of a pre-detection function in the scanning code processing process, can automatically enlarge the QR code of ultra-long distance even if it is indistinguishable by the naked eye.
2. Defective QR code
Contamination of the QR code is also a situation that households often encounter in daily scanning. Emergence, the unified scanning code service is based on a number of computer vision technologies, which can greatly improve the recognition rate of complex scenes.
Of course, the HMS Core unified code scanning service not only supports the scanning of defaced QR codes, but also can successfully scan codes when encountering scenes such as reflections and dark light, and even when the QR code is pasted on the product with curved surfaces or edges; You scan the code while walking, and the blurred QR code at this time does not affect the accuracy of the code scan.
3. Multi-code identification
When inventorying, sending and receiving goods in the warehouse, it is often encountered that the goods are filled with barcodes, and if the workers scan the barcodes one by one, the efficiency is very low. Multi-code identification can help warehouse inventory, express delivery and other scenarios to identify multiple codes at one time, improving business processing efficiency. In multi-code recognition mode, Scan Kit can recognize up to 5 codes of unlimited types at one time.
4. Scan code from multiple angles
Sometimes due to environmental constraints, we may not be able to scan the QR code from the front angle. The unified scanning service is based on automatic detection and rotation correction capabilities, and the recognition area is wider (side and side +45°), allowing users to scan from any angle. The QR code can be automatically corrected and quickly recognized, even if the location is inconvenient, it can be recognized correctly, thus improving the application scanning flexibility and recognition rate.
Development steps
The unified code scanning service provides multiple access methods. At least 5 lines of code can have powerful code scanning capabilities. Developers can directly use the default scanning code page provided by Scan Kit, or based on the sample code provided by Scan Kit, quickly and automatically Define the scanning function. Below I will take Default View Mode as an example to show the specific integration steps.
Preparation before development
- Configure the HMS Core maven warehouse address in the project-level "setting.gradle"
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
// 配置HMS Core SDK的Maven仓地址。
maven { url 'https://developer.huawei.com/repo/' }
}
}
dependencyResolutionManagement {
...
repositories {
google()
mavenCentral()
// 配置HMS Core SDK的Maven仓地址。
maven { url 'https://developer.huawei.com/repo/' }
}
}
2. Add compilation dependencies to the app-level build.gradle
dependencies{
implementation 'com.huawei.hms:scanplus:2.4.0.302'
}
- Configure Obfuscation Script
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.**{*;}
- Specify camera permissions and file read permissions in "AndroidManifest.xml", and dynamically apply for permissions
<!--相机权限-->
<uses-permission android:name="android.permission.CAMERA" />
<!--读文件权限-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
// CAMERA_REQ_CODE为用户自定义,用于接收权限校验结果的请求码。
this.requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE}, CAMERA_REQ_CODE);
- Check whether the corresponding permissions are enabled, and decide whether to continue scanning the code.
// 实现“onRequestPermissionsResult”函数接收校验权限结果。
final int PERMISSIONS_LENGTH = 2;
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
// 判断“requestCode”是否为申请权限时设置请求码CAMERA_REQ_CODE,然后校验权限开启状态。
if (requestCode == CAMERA_REQ_CODE && grantResults.length == PERMISSIONS_LENGTH && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
// 调用扫码接口,构建扫码能力。
...
}
}
Build scanning function
- Create scan code option parameters according to actual needs.
// “QRCODE_SCAN_TYPE”和“DATAMATRIX_SCAN_TYPE”表示只扫描QR和Data Matrix的码
HmsScanAnalyzerOptions options = new HmsScanAnalyzerOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE, HmsScan.DATAMATRIX_SCAN_TYPE).create();
- Call the static method startScan of ScanUtil to start the Default View scan code page. Users can scan the code with the camera, or detect the code in the picture through the "Import Picture" button on this page.
ScanUtil.startScan(this, REQUEST_CODE_SCAN_ONE, options);
- Implement the callback interface to receive the scan code result. Both the camera scan code and the imported image scan code are returned through this interface.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK || data == null) {
return;
}
if (requestCode == REQUEST_CODE_SCAN_ONE) {
// 导入图片扫描返回结果
HmsScan obj = data.getParcelableExtra(ScanUtil.RESULT);
if (obj != null) {
// 展示解码结果
showResult(obj);
}
}
}
Learn more details>>
Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee
Follow us to know the latest technical information of HMS Core for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。