How to Scan QR Code in Android

Posted By : Piyush Dubey | 11-Apr-2017


Today I am going to write blog on how to scan  Qrcode using Mobile Vison Api .I have found it most efficient in scanning QR code.

Followings steps are required to achieve this task.

1. Add  compile 'com.google.android.gms:play-services-vision:10.2.1' dependency in build.gradle of app.

2. Design the UI of the app which include SurfaceView for camera preview and textview for storing qrcode 
   information.

3. Using BarcodeDetector.Builder set the  barcode format to QRcode.
 
4. Using Camera Source set the preview size for scanning the Qrcode.The dimension of the preview size should
   be set to the dimension of SurfaceView as defined in xml.

5. Attach callback to the SurfaceView.Inside the Surface Created method start the CameraSource for Scanning 
   the QRcode and in surfaceDestroyed method stop the CameraSource.

6. We can set Processor to Barcodedetector and obtain the QR Code value read and set it to the textview.That's it.
   

  Complete implementation of code can be found here:https://github.com/piyushdubey529/qrcodeScanner

THANKS

About Author

Author Image
Piyush Dubey

Piyush is a good learner & innovative. He is passionate about coding and likes to watch cricket & listening music. He has worked on projects like ZipPosRepots, ZipOrdering.

Request for Proposal

Name is required

Comment is required

Sending message..