quickie

quickie is a Quick Response (QR) Code scanning library for Android that is based on CameraX and ML Kit on-device barcode detection. It's an alternative to ZXing and written in Kotlin. quickie features:

  • Easy API for launching the QR scanner and receiving results by using the AndroidX Activity Result API
  • Modern design, edge-to-edge scanning view with multilingual user hint
  • Android Jetpack CameraX for communicating with the camera and showing the preview
  • Firebase ML Kit on-device barcode recognition and decoding (no network connection required)

Download

There are two different flavors available on jcenter():

Bundled Unbundled
ML Kit model is bundled inside app (independed of Google Services) ML Kit model will be automatically downloaded via Play Services (after app install)
additional 1.1 MB size per ABI (you should use AAB or ABI splitting) smaller app size
V2 barcode model is used (possibly faster, more accurate) currently V1 will be downloaded
// bundled:  
implementation("com.g00fy2.quickie:quickie-bundled:0.1.0")

// unbundled:
implementation("com.g00fy2.quickie:quickie-unbundled:0.1.0")

Quick Start

To use the QR scanner simply register the ScanQRCode() ActivityResultContract together with a callback during initialization or in the onCreate() lifecycle of your Activity/Fragment and call launch(null) anywhere to start it:

private val scanQrCode = registerForActivityResult(ScanQRCode()) { handleResult(it) }

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    ...

    binding.buttonQrScanner.setOnClickListener { scanQrCode.launch(null) }
}

⚠️ You can't register the ActivityResultContract inside of the OnClickListener. This will fail since the code get's executed after the onCreate lifecycle!

Check out the samples inside this repo or visit the Activity Result API documentation for more information.

Responses

The callback you add to the registerForActivityResult will receive an instance of the sealed QRResult class:

  1. QRSuccess when ML Kit successfully detected a QR code
    1. wraps a QRContent object
  2. QRUserCanceled when the activity got canceled by the user
  3. QRMissingPermission when the user didn't accept the camera permission
  4. QRError when CameraX or ML kit threw an exception
    1. wraps the exception

Content

quickie wraps the content type of the QR code detected by ML Kit inside an sealed QRContent class. All of them provide the rawValue.

Currently supported types are:
Plain, Wifi, Url, Sms, GeoPoint, Email, Phone, ContactInfo, CalendarEvent

See the ML Kit Barcode documentation for further details.

Customization

The library is designed to behave and look as generic as possible. Currently it's not possible to change the UI, but there are plans to add customizations in future releases.

Screenshots

quickie-device-demo

Release state

quickie relies on Google Jetpack libraries which are in pre-release state. CameraX has no stable release version yet and the Activity Result API is part of the latest AndroidX Activity and Fragment beta releases. Here is what Google says about this release state:

  • Beta releases are functionally stable and have a feature-complete API surface.
  • They are ready for production use but may contain bugs.

You should consider quickie to be in beta state too. I will raise the version to 1.0 once all dependent libraries hit stable.

Requirements

  • AndroidX
  • Min SDK 21+
  • (Google Play Services available on the end device if using quickie-unbundled)

GitHub