Since some of the answers are outdated, I would like to provide my own -
To integrate ZXing library into your Android app as suggested by their Wiki, you need to add 2 Java files to your project:
Then in Android Studio add the following line to build.gradle file:
dependencies {
....
compile 'com.google.zxing:core:3.2.1'
}
Or if still using Eclipse with ADT-plugin add core.jar file to the libs subdirectory of your project (here fullscreen Windows and fullscreen Mac):
Finally add this code to your MainActivity.java:
public void scanQRCode(View v) {
IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult result =
IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (result != null) {
String contents = result.getContents();
if (contents != null) {
showDialog(R.string.result_succeeded, result.toString());
} else {
showDialog(R.string.result_failed,
getString(R.string.result_failed_why));
}
}
}
private void showDialog(int title, CharSequence message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton(R.string.ok_button, null);
builder.show();
}
The resulting app will ask to install and start Barcode Scanner app by ZXing (which will return to your app automatically after scanning):
Additionally, if you would like to build and run the ZXing Test app as inspiration for your own app:
Then you need 4 Java files from GitHub:
And 3 Jar files from Maven repository:
(You can build the Jar files yourself with mvn package
- if your check out ZXing from GitHub and install ant and maven tools at your computer).
Note: if your project does not recognize the Jar files, you might need to up the Java version in the Project Properties: