Android - Barcode Scanner
Solution 1:
ZXing is open source! If you realy want to implement your own barcode scanner then have a look in the source.
You can browse the code online here, it is licensed as Apache Licence 2.0.
Solution 2:
Zxing has a great Intent-based API, and is designed to be used as a secondary app. I would recommend checking to see if the user has the Zxing app installed, and if not, redirect them to the Google Play store to download it.
Solution 3:
I know I am quite late to answer here but all the folks looking for an updated answer to this question, no more a need to depend on third party apis, Google offers Barcode Scanning APIs via Google Play Services 7.8. Refer to CodeLabs, Documentation, Github Sample for more information.
Solution 4:
If you want to implement a barcode scanner inside your app without depending on other apps you can use ZXing Android Embedded, you just need to declare its dependecies in your gradle dependecies and use its features inside your app.
To use it add the following to your build.gradle files (project/module):
repositories {
jcenter()
}
dependencies {
compile'com.journeyapps:zxing-android-embedded:3.2.0@aar'compile'com.google.zxing:core:3.2.1'compile'com.android.support:appcompat-v7:23.1.0' // Version 23+ is required
}
android {
buildToolsVersion '23.0.2' // Older versions may give compile errors
}
Now in your code you start a scanning activity this way:
publicvoidscanBarcode() {
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
integrator.setPrompt("Scan the barcode");
integrator.setCameraId(0); // Use a specific camera of the device
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
}
and process the results this way:
publicvoidonActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResultscanResult= IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null && scanResult.getContents() != null) {
Stringcontent= scanResult.getContents().toString();
// content = this is the content of the scanned barcode// do something with the content info here
}
}
More info can be found on the ZXing Android Embedded github repo, link below.
Source: https://github.com/journeyapps/zxing-android-embedded
Post a Comment for "Android - Barcode Scanner"