Qadir Hussain
Qadir Hussain

Reputation: 8856

How to store the Generated QR-Code as an image in SDCard (ZXing library)

I m making an app based on QR code. I have to Generate a QR-Code of a specific String and also I have to save the generated QR-Code in SD card. is it possible using the Zxing Library.

So for I am able to generate the QR-Code, using the following code.

Note:I m calling the QR-Code Scanner via Intent. I m inserting the input using an EditText Field right now. see code below

public class MainActivity extends Activity {

EditText edQR_Field;
Button btnGenerate_QR_Code;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnGenerate_QR_Code = (Button) findViewById(R.id.button1);
    edQR_Field = (EditText) findViewById(R.id.editText1);

    btnGenerate_QR_Code.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            String input = edQR_Field.getText().toString();

            Intent intent = new Intent(
                    "com.google.zxing.client.android.ENCODE");

            intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
            intent.putExtra("ENCODE_DATA", input);
            intent.putExtra("ENCODE_FORMAT", "QR_CODE");
            intent.putExtra("ENCODE_SHOW_CONTENTS", false);
            startActivityForResult(intent, 0);

            Toast.makeText(MainActivity.this, input, Toast.LENGTH_SHORT)
                    .show();

        }
    });

}

 }

and I m getting this.

enter image description here

Question

I just want to save this Generated QR-Code in the SD card of my android device.

Regards Qadir Hussain

Upvotes: 0

Views: 4524

Answers (3)

Sean Owen
Sean Owen

Reputation: 66886

You can't cause the image to be saved, or get the image back, if you're integrating by Intent. However the user can save the image by pressing Menu and Share.

Instead you will simply need to embed the core library from the project and call it to encode the image. Then you can display or save or do what you like.

You can see how it's done in the app here, and reuse parts of this code: https://code.google.com/p/zxing/source/browse/trunk/android/src/com/google/zxing/client/android/encode/EncodeActivity.java

Upvotes: 2

Hamad
Hamad

Reputation: 5152

hmm! ok then see this link. in this link the ZXing library is used! and it is described simply! http://www.mysamplecode.com/2012/09/android-generate-qr-code-using-zxing.html

let me know is it usefull?

Upvotes: 0

Hamad
Hamad

Reputation: 5152

Complete Answer:

Text is a great Java PDF library. They also have an API for creating barcodes. You don't need to be creating a PDF to use it.

This page has the details on creating barcodes. Here is an example from that site:

BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCodeType(codeEAN.EAN13);
codeEAN.setCode("9780201615883");
Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);

The biggest thing you will need to determine is what type of barcode you need. There are many different barcode formats and iText does support a lot of them. You will need to know what format you need before you can determine if this API will work for you.

Upvotes: 1

Related Questions