How to generate a QR Code for an Android application?

Radu picture Radu · Jan 10, 2012 · Viewed 170.2k times · Source

I need to create a qrcode in my android application, and I need a library or source code that lets me create a QR Code in an Android app.

The library I need must:

  1. not leave a watermark (like onbarcode library)
  2. not use web service API to create the qrcode (like Google's library zxing)
  3. not need 3rd party installers (like QR Droid)

I already created such code for iPhone (Objective-C) but I need a quick fix for Android until I have time to make a QR Code generator of my own. It's my first android project so any help will be appreciated.

Answer

Stefano picture Stefano · Aug 13, 2014

with zxing this is my code for create QR

 QRCodeWriter writer = new QRCodeWriter();
    try {
        BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
            }
        }
        ((ImageView) findViewById(R.id.img_result_qr)).setImageBitmap(bmp);

    } catch (WriterException e) {
        e.printStackTrace();
    }