Barcode scanning library for HarmonyOS, using ZXing for decoding.
The project is loosely based on the ZXing Barcode Scanner application, but is not affiliated with the official ZXing project.
Features:
A sample application is available here.
Add the following to your build.gradle
file:
Solution 1: local source integration, users can be customized modifications
Copy zxing_embedded folder to project directory;
Modify Settings. Gradle under the project to add dependencies to this module as follows:
Solution 2: Local HAR package integration
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
Solution 3: remote maven repo integration Add the following code in the entry's gradle
implementation 'com.gitee.baijuncheng-open-source:Zxing-Embedded:1.0.0'
Launch the intent with the default options:
new IntentIntegrator(this).initiateScan(); // `this` is the current Ability
// Get the results:
@Override
protected void onAbilityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseAbilityResult(requestCode, resultCode, data);
if (result != null) {
String toast;
if (result.getContents() == null) {
toast = "Cancelled from fragment";
} else {
toast = "Scanned from fragment: " + result.getContents();
}
// At this point we may or may not have a reference to the activity
displayToast(toast);
}
return;
}
Use from a Fraction:
IntentIntegrator.forSupportFragment(ScanFraction.this).initiateScan();// `this` is the current Fraction
// If you're using the support library, use IntentIntegrator.forSupportFragment(ScanFraction.this) instead.
Customize options:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
See [IntentIntegrator][https://gitee.com/baijuncheng-open-source/zxing-embedded] for more options.
While this is not the primary purpose of this library, it does include basic support for generating some barcode types:
if (source != null) {
rawResult = decoder.decode(source);
}
if (rawResult != null) {
if (resultHandler != null) {
BarcodeResult barcodeResult = new BarcodeResult(rawResult, sourceData);
InnerEventinnerEvent=InnerEvent.get(zxing_decode_succeeded,barcodeResult);
PacMap pacMap = new PacMap();
innerEvent.setPacMap(pacMap);
handler.sendEvent(innerEvent);
}
} else {
if (resultHandler != null) {
InnerEvent innerEvent = InnerEvent.get(zxing_decode_failed);
handler.sendEvent(innerEvent);
}
}
if (resultHandler != null) {
List<ResultPoint> resultPoints = BarcodeResult.transformResultPoints(decoder.getPossibleResultPoints(), sourceData);
InnerEvent innerEvent = InnerEvent.get(zxing_possible_result_points, resultPoints);
handler.sendEvent(innerEvent);
}
requestNextPreview();
No customization of the image is currently supported, including changing colors or padding. If you
require more customization, copy and modify the source for the encoder.
To change the orientation, specify the orientation in your config.json
and let the ManifestMerger
to update the Ability's definition.
Sample:
"abilities": [
{
"orientation": "unspecified",
"name": "com.harmonyos.zxingembedded.journeyapps.barcodescanner.CaptureActivity",
"icon": "$media:icon",
"description": "$string:ability_description",
"label": "zxing_harmonyos_embedded",
"type": "page",
"launchType": "standard"
}
]
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setOrientationLocked(false);
integrator.initiateScan();
For more advanced options, look at the Sample Application, and browse the source code of the library.
This is considered advanced usage, and is not well-documented or supported.
The camera permission is required for barcode scanning to function. It is automatically included as part of the library. It is requested at runtime when the barcode scanner is first opened.
When using BarcodeView directly (instead of via IntentIntegrator / CaptureActivity), you have to
request the permission manually before calling BarcodeView#resume()
, otherwise the camera will
fail to open.
./gradlew assemble
To deploy the artifacts the your local Maven repository:
./gradlew publishToMavenLocal
You can then use your local version by specifying in your build.gradle
file:
repositories {
mavenLocal()
}
Licensed under the Apache License 2.0
Copyright (C) 2012-2018 ZXing authors, Journey Mobile
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型