Generate QR Code Using Zxing Android Studio Programmatically

Hello, geeks. Welcome to Generate QR Code Using Zxing Android Studio example tutorial.

You will learn how to generate QR code in Generate QR Code Using Zxing Android Studio example.

You can generate QR Code from any string using ZXing library.

We will also save generated QRCode to internal storage.

First check output then we will develop Generate QR Code Using Zxing Android Studio example.

Download Source Code For Generate QR Code Using Zxing Android Tutorial

[sociallocker]Download Source Code [/sociallocker]

Creating generate create QR Code ZXing Android step by step

Step 1: Create a new project in Android Studio.

Step 2: Updating build.gradle(Module:app) file

add following code into dependencies{} 

Step 3: Adding colors in colors.xml

Move to res->values->colors.xml directory and add following

Step 4: Updating AndroidManifest.xml file

 add required permissions between <manifest>….</manifest> tag.

Note: If you are targeting SDK version above 22 (Above Lollipop)  then you need to ask a user for granting runtime permissions. Check marshmallow runtime permission for more information.

Final code for AndroidManifest.xml file

Step 5: Updating activity_main.xml file

 Copy and paste below source code in activity_main.xml file

Step 6: Preparing class

Add following source code in class

Step 7: Description of

Following method saves the QRcode image.

IMAGE_DIRECTORY is the folder in which image is saved.

Image will be saved in the internal memory of android device.

You can change the value of IMAGE_DIRECTORY variable to customize the location to which you want to save generated QRCode image.

Below method will generate QRCode from given string.

Above method will use various classes of ZXing library to create QRCode from given string.

Implementation of a button click.

If there is no string is entered, a message is printed to enter a string.

Otherwise, QRcode is generated and saved.

So all for generate create QR code ZXing Android Studio programmatically example tutorial. Thank you.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

34 Responses

  1. Steve says:

    Your King bro, thanks 🙂

  2. Babuli says:

    Please let me know how to send a payment request to the customer for UPI payment using android

  3. Firas says:

    please consider to change the code below as it is consuming a lot of resources :

    Instead of this in the loop:
    for loop

    do this:
    int bgColor = getResources().getColor(;
    int color = getResources().getColor(R.color.white);

    for loop

  4. Panneer says:

    sir not save in folder
    pls help me

  5. Yan Myo Kyaw says:

    It is very help to me. Thanks bro.
    Be happy!

  6. Sing Song says:

    Hey,, i generate a QR using this one. my problem is…. how to make the generated QR pop out in my screen?

    • Govlog says:

      bitmap = TextToImageEncode(etqr.getText().toString());
      This code is generate QR, you can used it in dialog pop up

  7. FenuShui says:

    How to add Images in the center of the QR code using this method ?

  8. Nikhil says:

    i have one requirement.
    Ex if i am taking one image how to capture inside image value,on that value i will shows in edittext.

  9. kevin says:

    how to insert the image from qrcode into database? thank you 🙂

  10. Budyanto says:

    getresources().getcolor() is deprecated
    The Best Approach to use :
    ContextCompat.getColor(context, R.color.color_name)

  11. Vincent Van Fundal says:

    How can you make a qrcode generator with multiple line texts for input? For example you may want the user to input Name, Age and Gender and you may want it to convert to a single qr code

  12. Emanuele says:

    Where is the rest of the article? It stops at the beginning of step 4.

    • Hardik Parsania says:

      It may happen for many reasons like you have ad blocker in your browser,slow internet connection or heavy load on your PC or browser etc.
      If you have ad blocker then please remove it first, and delete history of your browser. and again reload the page.
      P.S. : I am able to see full article on my laptop, I have checked in both chrome and mozilla.

  13. Josephis says:

    I have run my code successfully by your method !!

  14. Dinesh says:

    Cannot solve symbol DATA_MATRIX
    Help me

  15. halil says:

    hi buddy, I did all project work but app doesnt create anyfile which name is QRcodeDemonuts,app generate qrcode but not save in any file pls help me? thanks

  16. Sougata Roy says:

    Is there any way of reading a document (pdf, doc) and then converting the resource into a QR code?

  17. Florent says:

    my app is crashing .i did everything alike in the tutorial but still.

Leave a Reply

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