As a complement to the answer of the companion @Casca
Installation
Installation of the unit:
compile 'com.journeyapps:zxing-android-embedded:3.5.0'
Start capture
To initialize a quick capture of a Activity
new IntentIntegrator(this).initiateScan();
If fragment is used
IntentIntegrator.forFragment(this).initiateScan();
Personalization
Can be customized, such as the types of codes to be scanned with setDesiredBarcodeFormats
the text that is displayed per screen setPrompt
the rear camera 0
or the front 1
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan a barcode");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
Read Result
To intercept the scan result is done with onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null) {
if(result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
Extracted from: link
More examples
This Project-of-test repository contains several examples of use