I am new to Zxing. I am doing barcode conversion using zxing in my android application. Can anyone guide me how to include zxing to android device.
3 Answers
If the zxing barcode scanner is installed in the mobile, its very easy:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");//for Qr code, its "QR_CODE_MODE" instead of "PRODUCT_MODE"
intent.putExtra("SAVE_HISTORY", false);//this stops saving ur barcode in barcode scanner app's history
startActivityForResult(intent, 0);
and in OnActivityResult
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = data.getStringExtra("SCAN_RESULT"); //this is the result
} else
if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
If its not installed: u can put this code in try-catch block and catching the exception, u can do this:
Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
startActivity(marketIntent);
So it redirects the app to android market
and ur app continues running once if the barcode scanner
is installed.
If u dont want to use the other app in ur app, U have to download zxing library and try using the classes from core.jar file(it is created using apache ant). Follow this tutorial to do that: https://github.com/zxing/zxing/wiki/Getting-Started-Developing
All Intent options can be found here:

- 6,103
- 4
- 39
- 56

- 13,560
- 9
- 60
- 109
-
Thank you, this is more informative. i downloaded the code from google. and whenever i compile the built script, i am getting error. can we download the core.jar from net.? or do you have core.jar file. – RAAAAM Jan 03 '12 at 09:17
-
core.jar file should be generated on your own. – Seshu Vinay Jan 03 '12 at 09:20
-
coz its its not portable – Seshu Vinay Jan 03 '12 at 09:21
-
u have to use apache ant to generate core.jar – Seshu Vinay Jan 03 '12 at 09:21
-
but its rather difficult to use that – Seshu Vinay Jan 03 '12 at 09:23
-
It will be easy if u ask the user to install the default barcoder app – Seshu Vinay Jan 03 '12 at 09:23
-
just giving an intent gives u the result – Seshu Vinay Jan 03 '12 at 09:24
-
i tried but the core.jar is getting error. i cant able to generate the code.jar using ant. i am new to ant. can you able to generate the jar. – RAAAAM Jan 03 '12 at 09:25
-
i downloaded core.jar from http://www.java2s.com/Code/Jar/z/Downloadzxing16corejar.htm. is this applicable to use.?? – RAAAAM Jan 03 '12 at 09:26
-
http://code.google.com/p/zxing/wiki/GettingStarted i followed this and created core.jar file succesfully – Seshu Vinay Jan 03 '12 at 09:27
-
If u follow the above method, no need to generate core.jar file. Just u can get the barcode scanned using a simple intent – Seshu Vinay Jan 03 '12 at 09:29
-
i followed the above link. i got core.jar in core file. and i applied into my application.but even iam getting error in android application. – RAAAAM Jan 03 '12 at 10:06
-
thats y follow this simple method – Seshu Vinay Jan 03 '12 at 10:08
-
I am still getting error, shows that no activity found. – RAAAAM Jan 03 '12 at 10:39
-
i already said about that, u will get error if barcode scanner is not installed in the mobile – Seshu Vinay Jan 03 '12 at 10:58
-
put that code in try catch block – Seshu Vinay Jan 03 '12 at 10:58
-
catch the exception and add the above code under exception as i mentioned in the above answer – Seshu Vinay Jan 03 '12 at 11:01
-
It seems that it doesn't work anymore... I've always use it but now I get the error: "No activity found to handle intent [...]" – ivy Oct 16 '12 at 07:38
-
The link can be found here : https://github.com/zxing/zxing/blob/master/android/src/com/google/zxing/client/android/Intents.java – phuwin Jul 13 '16 at 11:51
You need to download the Zing's .Jar file & add in to your application folder. Then you can call classes & methods of it.

- 29,392
- 25
- 90
- 143
-
2
-
-
2@Siddharth - yes, it does. It's open source and this is a common implementation choice. – Mike Repass Sep 28 '12 at 17:26
Step by step to setup zxing 3.2.1 in eclipse
- Download zxing-master.zip from "https://github.com/zxing/zxing"
- Unzip zxing-master.zip, Use eclipse to import "android" project in zxing-master
- Download core-3.2.1.jar from "http://repo1.maven.org/maven2/com/google/zxing/core/3.2.1/"
- Create "libs" folder in "android" project and paste cor-3.2.1.jar into the libs folder
- Click on project: choose "properties" -> "Java Compiler" to change level to 1.7. Then click on "Android" change "Project build target" to android 4.4.2+, because using 1.7 requires compiling with Android 4.4
- If "CameraConfigurationUtils.java" don't exist in "zxing-master/android/app/src/main/java/com/google/zxing/client/android/camera/". You can copy it from "zxing-master/android-core/src/main/java/com/google/zxing/client/android/camera/" and paste to your project.
- Clean and build project. If your project show error about "switch - case", you should change them to "if - else".
- Completed. Clean and build project

- 1,145
- 15
- 25