How to create a simple QR Code Scanner and publish it on play store in 5mins
Tags: android, kotlin, opensource, java
Published: 2023-07-17 18:00:34


<img src = "https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v23fedjog8qi2bj3p6kw.gif"/>


**👋Hello guyz,
I want you to checkout my QR Code Scanner on [Play Store](https://play.google.com/store/apps/details?id=com.khandev.qrcodescanner)**
**source code of my QR code scanner [github](https://github.com/khan-mujeeb/QR-Code-scanner)**

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pfwtj5k28x6t2vi4mxwx.gif)

</br>
</br>
## 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.

</br>


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

</br>
**Include in your top-level settings.gradle file**

```kotlin
dependencyResolutionManagement {
  repositories {
    google()
    mavenCentral()
  }
}
```

**Add the dependency of a code scanner in the app/build.gradle**
```kotlin
dependencies {
  implementation 'com.google.android.gms:play-services-code-scanner:16.0.0'
}
```

<br>

**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**

```xml
<application ...>
  ...
  <meta-data
      android:name="com.google.mlkit.vision.DEPENDENCIES"
      android:value="barcode_ui"/>
  ...
</application>
```

</br>
</br>

### Step 2: Code for Scan Code
</br>
**Get an instance of GmsBarcodeScanner**
```kotlin
val scanner = GmsBarcodeScanning.getClient(this)
// Or with a configured options
// val scanner = GmsBarcodeScanning.getClient(this, options)
```

</br>

**Request a code scanning by calling startScan()**
```kotlin
scanner.startScan()
    .addOnSuccessListener { barcode ->
        val result: String? = barcode.rawValue
    }
    .addOnCanceledListener {
        // Task canceled
    }
    .addOnFailureListener { e ->
        // Task failed with an exception
    }
```

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](https://play.google.com/store/apps/details?id=com.khandev.qrcodescanner)**

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](https://github.com/khan-mujeeb), [Medium](https://medium.com/@mujeebkhan1831) and [LinkedIn](https://www.linkedin.com/in/mujeeb-ur-rahman-khan/)