Open-source project
mylhyl/Android-Zxing avatar
mylhyl/Android-Zxing

Android-Zxing wraps ZXing in a customisable Android scanner view

android google zxing 可配置扫描框、线样式 ,生成二维码(文字、联系人)

570 stars163 forksJavaLicense varies

At a glance

What is it?
Android-Zxing is a Java library for Android that puts ZXing behind a ScannerView you can drop into a layout, with configurable scan frame, laser line and hint text, plus QR code generation and decoding from images. It suits Android developers who want a scanner with their own look rather than a stock camera screen.
Who is it for?
Adopt Android-Zxing if you are building an Android app that scans codes and need the scan frame, laser line and hint text to match your design, or if you need to generate QR codes and decode codes from images in the same library. Do not adopt it for a JavaScript application, since this is an Android view and an Activity lifecycle, and do not plan around new releases, because the last tagged version is 2.2.0 from January 2021 even though the repository itself receives commits.
Can I use it commercially?
Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
Is it still maintained?
Yes. The repository last received commits 6 days ago.
What is it written in?
Mainly Java, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

A view that wraps ZXing rather than a camera activity

Android-Zxing is a Java library for Android that provides a configurable scan frame and line style, and can generate QR codes from text or from contact details. The description names ZXing as the underlying engine, and the important architectural decision is that the scanner is a view you embed rather than a camera Activity you launch. The documentation says you can use ScannerView directly in a layout xml, and the sample sits in the repository at sample/src/main/java/com/mylhyl/zxing/scanner/sample/OptionsScannerActivity.java, which shows the intended shape. Embedding rather than launching matters for more than convenience. A camera Activity owns the whole screen and hands control back through a result code, which is workable but rigid. A view lets you put the scanner inside your own layout, next to your own controls, with your own toolbar, and it means the scan result comes to your code as a callback rather than as an intent extra. The repository layout follows the same structure, with the library in zxingscanner/ and a sample/ module holding the working example.

The dependency story has a JCenter wrinkle worth reading first

The first section of the project documentation is a migration note rather than a feature list, and that is the most immediately useful thing a new adopter will encounter. JCenter has been announced as no longer maintained, so the documentation splits into two routes. For older versions, the instruction is to add an Aliyun mirror repository to the build.gradle file in the project root, and for newer versions the repository is JitPack. The two blocks are nearly identical apart from the URL:

gradle
 allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
    }
 }
gradle
 allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
 }

The dependency coordinates themselves are the other half of the story. The library is published as com.mylhyl:zxingscanner:2.2.0, and the documentation also states that the ZXing core library is already integrated into this project, so for an online build you only need to add the one dependency:

gradle
compile 'com.mylhyl:zxingscanner:2.2.0'

If you would rather not use a repository at all, the project also ships an offline jar with the ZXing core library included, downloadable from the preview/lib directory of the repository, or built yourself with a gradlew makeJar command. The alternative is to depend on the core library directly and supply it yourself.

gradle
compile 'com.google.zxing:core:3.4.0'

Dropping the view into a layout, and the lifecycle that follows

Using the scanner in a layout takes four attributes, which is the whole of the markup you need:

xml
<com.mylhyl.zxing.scanner.ScannerView
    android:id="@+id/scanner_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

What that snippet does not show is the part that costs people an afternoon. The view is tied to the camera and to the Activity lifecycle, and the documentation calls this out with a note about using it in the lifecycle. You override onResume and call mScannerView.onResume() so the camera starts, and you override onPause and call mScannerView.onPause() so it stops and releases the device. The order matters in the snippets given, with the view call placed before super.onResume() in the resume case and before super.onPause() in the pause case, and both overrides are shown together in the documentation. Skipping the pause call is the classic mistake, and the symptom is that the camera indicator stays on after the user leaves the screen, or that the next attempt to open the scanner fails because the previous one still holds the device. The project also documents a way to keep scanning continuously after a successful scan by calling restartPreviewAfterDelay.

Results arrive as a parsed type you cast yourself

The result handling is where this library makes a deliberate choice, and it is worth understanding before you write the code. The library registers a listener with mScannerView.setOnScannerCompletionListener, and the callback signature takes three things: a Result which is the raw scan result, a ParsedResult which is the result type, and a Bitmap which is the captured image. The documentation is explicit that each project has different requirements, so the library hands the final processing back to you rather than deciding what an address book entry or a URI should do. You read the type with a single call:

java
ParsedResultType type = parsedResult.getType();

and then cast according to the type, with the sample showing the branches for ADDRESSBOOK, where an AddressBookParsedResult is cast and put into a bundle under Intents.Scan.RESULT, for URI, where a URIParsedResult is cast and its URI is written to the bundle, and for TEXT, where the raw text is written directly. The parsed result is the standard ZXing concept, so the type set is familiar to anyone who has used ZXing elsewhere. The captured Bitmap is worth noting too, because it lets you do something with the image itself rather than only with the decoded string. There is also a documented path for encrypted codes, where you rebuild a Result with the decrypted text and then run it through Scanner.parseResult to recover the type, which is a small but genuinely useful piece of functionality for anyone whose codes carry ciphertext.

QR generation and decoding from an image file

The library is not only a scanner. It can create QR codes, and the documented examples show a builder API with the type of content set explicitly. For a contact entry you set the parsed result type to ADDRESSBOOK and give it the contact URI, and for plain text you set the colour, the contents and optionally a logo bitmap, with the parsed result type defaulting to TEXT if you do not set it. The builder ends with build().encodeAsBitmap(), which returns a Bitmap you can put into an ImageView. Decoding works in the other direction as well, with two static entry points, one taking a picture path and one taking a Bitmap, each taking an OnScannerCompletionListener so that the same callback shape is used for live scans and for decoding an image that already exists. The feature list in the documentation is short and covers full screen or partial scanning, a customisable scan frame colour, the laser line style, the scan hint text, QR creation and QR recognition inside an image. The partial scanning point deserves a note, because a full screen scanner is the default in most libraries and constrains you to pointing the camera at nothing but the code.

Styles moved to ScannerOptions, and the camera permission is not optional

Two practical notes from the closing sections of the documentation. The first is an API migration. From version 1.6.0 the style settings on ScannerView were deprecated, and the new ScannerOptions object is the only place maintained, with the specific API documented in the ScannerOptions.Builder class. So if you are integrating with a recent release you should not look for the old setters at all, and if you are reading older tutorials you will find setters that no longer do anything. The second is the permission. The scanner needs the camera, and the manifest entry is:

xml
<uses-permission android:name="android.permission.CAMERA" />

The FAQ also points at a known issue with the setLaserFrameTopMargin method and the scan area offset, linked to issue 13, which is a good indication of the kind of layout fiddling you may need to do when the scanner sits inside your own view hierarchy rather than filling the screen. A final piece of the picture is the project state. The recent releases are 2.2.0 and 2.1.9, both from January 2021, with 2.1.8 from November 2020, so the published versions are old even though the repository itself is not archived and the last push was on 2026-10-17. The fork is still being worked on while the tags have not moved, which is the shape of a project that is maintained quietly rather than released often.

Editorial conclusion

Adopt Android-Zxing if you are building an Android app that scans codes and need the scan frame, laser line and hint text to match your design, or if you need to generate QR codes and decode codes from images in the same library. Do not adopt it for a JavaScript application, since this is an Android view and an Activity lifecycle, and do not plan around new releases, because the last tagged version is 2.2.0 from January 2021 even though the repository itself receives commits. Before you start, read the migration note about the JCenter shutdown and pick the repository that matches your build, and check which ZXing core version your ZXing dependency resolves to.

Frequently asked questions

What does the Android-Zxing library provide?

It provides a ScannerView for Android that wraps ZXing, supports full screen or partial scanning, a custom scan frame colour, a configurable laser line style and scan hint text, and it can also create QR codes from text or contact details and decode QR codes from an image file.

How do I add Android-Zxing to my Gradle build?

For an online build, add the dependency `compile 'com.mylhyl:zxingscanner:2.2.0'`, since the ZXing core library is already integrated. You also need to add a repository, either the Aliyun mirror for older versions or JitPack for newer ones, since JCenter has stopped being maintained. An offline jar is also provided in the repository.

How do I use the ScannerView in an Android layout?

Declare the com.mylhyl.zxing.scanner.ScannerView element in your layout xml with an id, a width and a height. You also have to call mScannerView.onResume() in onResume and mScannerView.onPause() in onPause, otherwise the camera is not released when the screen is left.

How do I get the QR code content in Android-Zxing?

Register a listener with mScannerView.setOnScannerCompletionListener. The callback receives the raw Result, the ParsedResult and the captured Bitmap, and you read the type with parsedResult.getType() before casting to the matching parsed result class such as AddressBookParsedResult or URIParsedResult.

Which licence does Android-Zxing use?

The repository does not state a licence in the information available here, and the license field is recorded as unknown. The project documentation covers the JCenter shutdown and the JitPack and Aliyun repository routes, but it does not describe licence terms, so confirm them with the project before shipping it in a closed source application.

Official sources

  1. Issues
  2. mylhyl/Android-Zxing on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/mylhyl-android-zxing.svg)](https://hysenlabs.com/projects/mylhyl-android-zxing)

Was this useful?