While scanning barcode in android is an old topic, some people still struggle to find a easy and reliable solution. So here is a tutorial on scanning as well as generating barcodes in android. We will use two libraries, one for scanning and one for generating. You can find the complete code of the demo app(written in Kotlin) at the this GitHub repo.


Scanning Barcode

To scan barcode we will use this library.

  • Add the following dependency in your app.gradle file.

  • Now you need to give camera permission to your app. Add the camera permission to your manifest file.

  • This library provides a view called ZBarScannerView which creates the camera interface with moving bar. Create an activity and change its view to ZBarScannerView.

  • Now you need to start and stop camera in onResume and onPause respectively.

  • To listen to barcode results you need to implement ZBarScannerView.ResultHandler interface, you will have to override the handleResult function. In the handle result function, fetch the data from the result object.


Generating Barcode

Generating barcode is even more easier than scanning. We will use this library for the purpose.

  • Add the following dependency in your app.gradle file.

  • Use the from(text) method in the QRCode object to create barcode of the given text.

  • You can also export the generated QR code to a file or have it in other formats, to find more functions and options go to the library’s GitHub README


The code for a compete working barcode demo app for the same is available at this GitHub Repo.



Gurleen Sethi

Android Developer and enthusiast, believes in developing products and content to help people. Likes to do deep thinking.


Escu · October 2, 2017 at 12:17 pm

Nice and useful post !

manishasingh · December 6, 2018 at 10:18 am

Thanks for sharing the post. Very nice and useful post to generate a barcode scanner in the android studio.

Move content to side in Drawer Layout Android - TheTechnoCafe · February 1, 2018 at 2:08 am

[…] Scanning and Generating Barcode in Android, Demo app in Kotlin […]

Leave a Reply

Your email address will not be published. Required fields are marked *

one + seventeen =