QR_CODE Scanner for Android

Q

“QR Codes” also knows as “Quick Response Codes”. Its two dimensional code (also known as Matrix Barcode ), and can be read easily by a mobile phone.
They fetch piece of information from temporary media and push that in your mobile phone. The reason why they are getting popular than normal Barcode is because they are able to capture more information(data, urls, texts and geo coordinates). Another reason for this  to go popular is because it can be scanned easily by mobile phones. You don’t need to have hand-held scanners to scan them.

Sounds really cool but as a developer it is as complicated as qrcode itself  🙂 .

After lot of searching i came across ZXing application  which returns the result via Intent. Most important thing is this is an open source code (pls correct me if i am wrong)

There are two ways of integrating this app

1- import QRCode scanner app from http://code.google.com/p/zxing/source/browse/trunk and start it from some trigger function like button press within your code which will ask you to download Barcode Scanner app from market. download it  and grab the result from onActivityResult() method of your Activity.

2- Copy some of the packages to your project and using camera you can scan the QRCode directly from your app. ( Which i have used 🙂 )

For both of above options the important thing you should do is

* create a .jar file of the source from core folder retrieved from github repo and add to your eclipse project.

for second option you need to add two more .jar files android-integration.jar and android-support-V4.jar (which i have put in the libs folder)

and need to add 5 packages

com.google.zxing.client.android

com.google.zxing.client.android.camera

com.google.zxing.client.android.encode

com.google.zxing.client.android.result

com.google.zxing.client.android.wifi

 

From your Activity start the SCAN activity like

Intent intent = new Intent(“com.google.zxing.client.android.SCAN”);
intent.putExtra(“SCAN_MODE”, “QR_CODE_MODE”);
startActivityForResult(intent, 0);

And in onActivityResult method add following code

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
 if (requestCode == 0) {
 if (resultCode == RESULT_OK) {
 String contents = intent.getStringExtra("SCAN_RESULT");
 t.setText(contents);
 String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
 // Handle successful scan
 } else if (resultCode == RESULT_CANCELED) {
 t.setText("Unable to scan the code");
 }
 }

That all you need to do to get it done :).

You can find the source code here.

About the author

mahesh.muley
By mahesh.muley

Category