I\'m writing this in mere desperation :) I\'ve been assigned to make a standalone barcode scanner (as a proof of concept) to an Android 1.6 phone.
For this i\'ve dis
Much Easier approach.
Just include dependency in your app level gradle file
compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar'
compile 'com.google.zxing:core:3.2.0'
Define one button in your xml file and and write below code in Java file in OnCreate()and inside the OnClick listener of button
new IntentIntegrator(this).initiateScan();
And write below code after OnCreate() of the Java file
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Log.d("MainActivity", "Cancelled scan");
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Log.d("MainActivity", "Scanned");
String st_scanned_result = result.getContents();
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
}
}
If you just need the core.jar from zxing, you can skip that process and get the pre-built JARs from the GettingStarted wiki page
Latest ZXing (2.2) doesn't have core.jar under core folder but you can obtain the core.jar from the zxing Maven repository here
If ant -f core/build.xml
says something like:
Unable to locate tools.jar. Expected to find it in
C:\Program Files\Java\jre6\lib\tools.jar
then set your JAVA_HOME
environment variable to the proper java folder. I found tools.jar in my (for Windows):
C:\Program Files\Java\jdk1.6.0_21\lib
so I set my JAVA_HOME
to:
C:\Progra~1\Java\jdk1.6.0_25
the reason for the shorter syntax I found at some site which says:
"It is strongly advised that you choose an installation directory that does not include spaces in the path name (e.g., do NOT install in C:\Program Files). If Java is installed in such a directory, it is critical to set the JAVA_HOME environment variable to a path that does not include spaces (e.g., C:\Progra~1); failure to do this will result in exceptions thrown by some programs that depend on the value of JAVA_HOME."
I then relaunched cmd (important because DOS shell only reads env vars upon launching, so changing an env var will require you to use a new shell to get the updated value)
and finally the ant -f core/build.xml
worked.
Have you seen the wiki pages on the zxing website? It seems you might find GettingStarted, DeveloperNotes and ScanningViaIntent helpful.
The
compile 'com.google.zxing:core:2.3.0'
unfortunately didn't work for me.
This is what worked for me:
dependencies {
compile 'com.journeyapps:zxing-android-embedded:3.0.1@aar'
compile 'com.google.zxing:core:3.2.0'
}
Please find the link here: https://github.com/journeyapps/zxing-android-embedded
Step by step to setup zxing 3.2.1 in eclipse