QR code scanner

hitansu jena picture hitansu jena · Mar 31, 2011 · Viewed 12.4k times · Source

I would like to create a QR code scanner in my app.

I went through the zxing ,but I could not understand it. I am interested in QR codes only.

All help is highly appreciated.

Answer

jengelsma picture jengelsma · Mar 31, 2011

Place a copy of the com.google.zxing.client.* source packages into your project. You can start the zxing scanning activity like this:

Intent intent = new Intent(this, CaptureActivity.class);
startActivityForResult(intent, 0);

In the same activity that you invoked the CaptureActivity in you can handle the result when the scan completes with the following onActivityResult method:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data != null) {
            String response = data.getAction();

            if(Pattern.matches("[0-9]{1,13}", response)) {
                // response is a UPC code, fetch product meta data
                // using Google Products API, Best Buy Remix, etc.          
            } else {
                // QR codes - phone #, url, location, email, etc. 
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(response));
                startActivity(intent);
            }
        }
    }   

Hope this helps.