In this blog we will know about how to generate QR Code. I have used many library that generate QR code but the best one is androinmads Library.
what is the QR code – QR is an acronym for Quick Response. It’s a smarter version of the barcode, and it was originally developed in Japan for the automotive industry. Machines can read QR codes more quickly than barcodes, and QR codes can store more data in less space too.
Generating QR code-
- add following dependency in your app level build.gradle file.
1 |
compile 'androidmads.library.qrgenearator:QRGenearator:1.0.3' |
- add following permission in your manifest for saving QR code.
1 |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> |
- generating bitmap of QR code and set into an ImageView.
1 2 3 4 5 6 7 8 9 |
QRGEncoder qrgEncoder = new QRGEncoder("company_id=" + companyId, null, QRGContents.Type.TEXT, (int) (MainActivity.screen_width / 1.5)); try { // Getting QR-Code as Bitmap Bitmap bitmap = qrgEncoder.encodeAsBitmap(); // Setting Bitmap to ImageView ((ImageView)profileView.findViewById(R.id.qr_image)).setImageBitmap(bitmap); } catch (WriterException e) { Log.v("QRERROR", e.toString()); } |
- Save QR Code as Image.
1 2 |
// Save with location, value, bitmap returned and type of Image(JPG/PNG). QRGSaver.save(savePath, edtValue.getText().toString().trim(), bitmap, QRGContents.ImageType.IMAGE_JPEG); |
For Scanning QR code look
References https://github.com/androidmads/QRGenerator