DEV Community

Mujeeb Khan
Mujeeb Khan

Posted on

How to create a simple QR Code Scanner and publish it on play store in 5mins

👋Hello guyz,
I want you to checkout my QR Code Scanner on Play Store

source code of my QR code scanner github

In this article I am going to tell you how you can also create your QR code scanner and publish it on Play Store.

Pre-requisite

  • Android Studio
  • basic idea of java/kotlin

Now it’s time to create our own QR Code in just 5mins.

Image description

Why Google Code Scanner

The Google code scanner API provides a complete solution for scanning codes without requiring your app to request camera permission, while preserving user privacy. This is accomplished by delegating the task of scanning the code to Google Play services and returning only the scan results to your app. All image processing occurs on the device and Google doesn't store the results or image data.

Step 1: Add the dependency of a Google code scanner in the build.gradle


Include in your top-level settings.gradle file

dependencyResolutionManagement {
  repositories {
    google()
    mavenCentral()
  }
}
Enter fullscreen mode Exit fullscreen mode

Add the dependency of a code scanner in the app/build.gradle

dependencies {
  implementation 'com.google.android.gms:play-services-code-scanner:16.0.0'
}
Enter fullscreen mode Exit fullscreen mode

Add meta-data in the manifest file so that Google Play services automatically download the scanner module to the device while your app is installed from the Play Store

<application ...>
  ...
  <meta-data
      android:name="com.google.mlkit.vision.DEPENDENCIES"
      android:value="barcode_ui"/>
  ...
</application>
Enter fullscreen mode Exit fullscreen mode

Step 2: Code for Scan Code


Get an instance of GmsBarcodeScanner

val scanner = GmsBarcodeScanning.getClient(this)
// Or with a configured options
// val scanner = GmsBarcodeScanning.getClient(this, options)
Enter fullscreen mode Exit fullscreen mode

Request a code scanning by calling startScan()

scanner.startScan()
    .addOnSuccessListener { barcode ->
        val result: String? = barcode.rawValue
    }
    .addOnCanceledListener {
        // Task canceled
    }
    .addOnFailureListener { e ->
        // Task failed with an exception
    }
Enter fullscreen mode Exit fullscreen mode

our basic QR code scanner is ready to scan qr code
you can do further improvement according to your need.

Guyzz don't forget to check my qr code scanner on Play Store

In next article we will learn how to publish our qr code scanner on play store.

Thank you for reading this article. If you found this helpful and interesting, please like and follow me for more such content.

If I got something wrong, mention it in the comments. I would love to improve.

Connect with me on GitHub, Medium and LinkedIn

Top comments (0)