Tuesday, February 21, 2012

Integrating Bar code scanner in Android

In most of common enterprise mobile app,There is need of integrating bar code scanning in mobile apps,Now I am feeling very happy to share the thoughts regarding this.There is library available for bar code scanning named ZXing that is open source and free available in many languages.you can download it from http://code.google.com/p/zxing/downloads/detail?name=ZXing-2.0.zip&can=2&q=

There are two way to integrate the ZXing lib for Android app.one is first we download ZXing apk from android market and then through intent we can integrate it.To implement this we need to force the client to download the ZXing apk in its own device.The second way is to integrate it like a part of application.But the clients usually don't want the first way,they want the app integrated in more compact way.So I am exploring the second way ,Follow the below mentioned steps to integrate ZXing library in your mobile application.
1.First down,load the library from link http://code.google.com/p/zxing/downloads/detail?name=ZXing-2.0.zip&can=2&q= .the extract it in your library,you will see many folders inside that.
2.Now create a android project in your Eclipse,and choose option create project from existing source,then browse the android folder of Zxing Folder that is unzipped form of downloaded library.Now there is a core folder inside your ZXing folder,might be there is jar file,If there is no jar file then download apache ant from link
http://ant.apache.org/bindownload.cgi .then run command ant -f build.xml .It will create jar file like core.jar.
3.Now add this core.jar in your android project.For this right click on project Go Build path ->Add External Archive then browse core.jar.It will be added in your library path.Now right click on project and Go on Properties,then on next window select android,after selecting you will see a check box having level
Is library? ,select this check box and select apply.
4.Create a new android project,and right Click on project go on properties select android,you will see an option for adding library,then add the project that was previously created in the form of library.
5.Now add some code in your main activity on Button Click
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
startActivityForResult(intent, 1);
public void onActivityResult(int requestcode,int resultcode,Intent intent)
{
if(resquestcode==1)
{
if(resultcode=RESULT_OK)
{
String resultvalue=intent.getStringExtra("SCAN_RESULT");
String format= intent.getStringExtra("SCAN_RESULT_FORMAT");
}
else
{
//Error
}
}

}
Now we should add the following code in our manifest file
in application tag.
Now Don't forget to add the most important thing,permission for camera.
in above or below application
6.Now the last important thing we should add a jar file that we created in 2 step to this project, and then build
and run your newly created integrated bar code scanner.

3 comments:

  1. Hi everybody,

    I have tried these steps, but when i add the android project (in Eclipse), i see a red "x" on the project's name on the Package Explorer of Eclipse. If i do all the steps i can't run the app because i get a message that my project has error(s), because of that red "x" on the android project.

    What could be wrong?

    Thank you in advance

    ReplyDelete
  2. In which step you are facing problem?Might be possible that when you add library you will see error.there may be many reason to have error,So please specify step,So that I can suggest you the right way.

    ReplyDelete
  3. I have done with all these steps correctly It just Installing the application on Device, & Doing Nothing all the steps have been done Successfully. plz suggest

    ReplyDelete