Android QR Code Decoder and Encoder


This is a port of the ZXing (version 2.1) project but reduced in size and scope. It can be used as a direct call from any Android project instead of using the ZXing Intents mechanism.

This project is an attempt to make working with QR codes in Android a bit easier.

Support me with a donation

Donate to this project


You can encode a String fairly easily using the following code:

Encode with a QR Code

//Encode with a QR Code image
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder("Hello", 
Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();

Encode with a Barcode

//Encode with a QR Code image
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder("12345678910", 
Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();

Encoding Activity Example

You can see an example of how to ecode a string as a Bitmap and display it on the screen by following along with the file.


You can decode what is being displayed by the camera by extending Activity and implementing both IDecoderActivity and SurfaceHolder.Callback. An easier option is just to extend the DecoderActivity and override the handleDecode() method, the CaptureActivity does exactly that and is a good example to follow.

//When you initialize the camera, start the DecoderActivityHandler
//decodeFormarts is a Collection of BarcodeFormat objects to decipher. NULL means all.
//characterSet should be NULL to get a callbak
//cameraManager is used to control the preview
public void surfaceCreated(SurfaceHolder holder) {
    DecoderActivityHandler handler = new DecoderActivityHandler(this, 

//handleDecode() is called when a code has been deciphered.
public void handleDecode(Result rawResult, Bitmap barcode) {
    drawResultPoints(barcode, rawResult);
    ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);
    handleDecodeInternally(rawResult, resultHandler, barcode);

Decoding and Capture Activity Example

You can see an example of how to decode an image by following along with the file. You will also find a minimal example of how to decode an image and display it's results by following the file.

Decoding Formats

Encoding Formats