Using ZXing (on Android), if you initiate a PDF417 barcode scan like this...
List<String> oDesiredFormats = Arrays.asList("PDF_417".split(","));
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan(oDesiredFormats);
... and you initiate an "all codes" (except PDF417 and maybe a few others) barcode scan like this...
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
... then how do you initiate a single barcode scan that will recognise both (all the standard codes, and PDF417)? Thanks in advance!
If you don't specify it, it will default to scanning for whatever the user has configured. This by default includes most formats but not PDF417. So, I think you'd have to enumerate all the formats here. It's not too hard, but do you really want that? usually you have a use case that is scanning for a few related formats at most.
Related
I am trying to read barcode with the help if ZXing library for android. in my app when I click a button I am taken to the barcode reader activity where I read the code with the help if ZXing reader. My app can successfully read QR codes at this point but the problem is I have to hold the camera at a certain distance/angle (not fixed btw) every time. So naturally i am going through a mini workout (exaggeration) while i reading a QR code. Also, i tried turning on the flash, but when i do it becomes more difficult task to read one. I have user mobile vison library which is very fast but it does not have flash light support at this moment (or i may not have found how to turn the flash light on).
I am guessing my problem has something to do with the resolution. the barcode is printed from a machine which uses thermal printer with very low resolution. Since i cannot change the resolution of the printer, is there a way to lower the resolution at which ZXing is reading the barcode?
(PS I got the idea of lower resolution form the fact that Mobile Vision let us change the resolution and I had problems with higher resolution reading).
I would prefer to use Mobile Vision if there is a way to turn the flash light on.
my code for barcode reading class looks like this
private ZXingScannerView mScannerView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mScannerView = new ZXingScannerView(this);
mScannerView.setAutoFocus(true);
//mScannerView.setFlash(true);
setContentView(mScannerView);
}
#Override
protected void onResume() {
super.onResume();
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
#Override
protected void onPause() {
super.onPause();
mScannerView.stopCamera();
}
#Override
public void handleResult(Result result) {
if (result.getText() != null) {
Intent qrCodeIntent = new Intent();
qrCodeIntent.putExtra("barcode", result.getText());
setResult(CommonStatusCodes.SUCCESS, qrCodeIntent);
Log.v("Code", result.getText());
Log.v("Code Format", result.getBarcodeFormat().toString());
mScannerView.stopCamera();
finish();
}
}
The qr
If I remember correctly, by default, ZXing uses all formats' filters to check an image against. I mean, it firstly scans if is, for example, EAN13, than if it is UPC-A, and so on until it gets to QR-parser.
It is possible to set specific decoders to the ZXing's scanning view. I am sure it will speed scanning process up.
I am getting faster experience by setting the following things. I need QR code scan. So, I set IntentIntegrator.QR_CODE.
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(false);
integrator.setOrientationLocked(true);
integrator.initiateScan();
I also remove camera auto focus from manifest.
N.B. I am using this library.
I'm trying to build a QR Code reader following this tutorial
http://code.tutsplus.com/tutorials/android-sdk-create-a-barcode-reader--mobile-17162
I managed to get everything working, except that I need the camera to be the front camera of my device instead of the rear camera. I can't find any place in the tutorial that allows me to change this. I tried following this answer, but I still could not get it to work.
Mainly, my issue is with importing the library. I get the following error.
operator is not allowed for source level below 1.7
When I set my compiler settings to 1.7, I get this
Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead
I'm not exactly very proficient with Android and I apologize if it might not be a good question.
So, any way for me to use ZXing with the front camera in my app? Any links?
Thank you very much.
The source code uses Java 7. Android does not require Java <= 6. You can see that the build provided in the project happily feeds Java 7 bytecode to dex and produces a working app. I am not sure what tool you are using that suggests otherwise. Maybe it is old.
You should not need to copy and compile the project's code though. Why is that necessary? use the core.jar file.
You don't need any of this to use the front camera. Just invoke by Intent (https://github.com/zxing/zxing/wiki/Scanning-Via-Intent) and set extra SCAN_CAMERA_ID to the ID of the camera you want -- usually 1 for the front one.
Example:
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
intent.putExtra("SCAN_CAMERA_ID", 1);
If you use IntentIntegrator, you can use setCameraId() to specify the front camera:
IntentIntegrator integrator = new IntentIntegrator(yourActivity);
integrator.setCameraId(1);
integrator.initiateScan();
After quite a few search i found how to use the front camera. There is this piece of code in com.google.zxing.client.android.camera.CameraConfigurationManager.java
public void openDriver(SurfaceHolder holder) throws IOException {
Camera theCamera = camera;
if (theCamera == null) {
theCamera = Camera.open();
if (theCamera == null) {
throw new IOException();
}
camera = theCamera;
}
theCamera.setPreviewDisplay(holder);
jus change the Camera.open() to Camera.open(1)
worked fine for me
I am trying to use zxing barcode inside one of my app to scan barcodes. I have used intent to start the barcode scanner on a button cick.
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
What I have found is that most barcode can scan fine but when I try to scan the ITF (Interleaved 2 of 5) barcode within my app it doesnt work but if I just use the zxing barcode scanner it works fine.
Now I have been searching for a while and have read that I can use ALLOWED_LENGTH. I couldnt find much information as to how to pass in this information to the scanner. I tried the following but its not really making any difference.
**int[] item = new int []{6, 7, 8, 9, 10, 11, 12, 13};**
**intent.putExtra("ALLOWED_LENGTHS", item);**
I added the two lines above to my code. Can someone please let me know what is the correct way to acheive this please.
Thanks in advance
Solution
intent.putExtra("SCAN_MODE", Intents.Scan.ONE_D_MODE);
Note: You should probably use the provided intents, instead of hard-coding the extras string
Explanation
This has nothing to do with allowed lengths. ITF is not one of the PRODUCT_MODE formats
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A,
BarcodeFormat.UPC_E,
BarcodeFormat.EAN_13,
BarcodeFormat.EAN_8,
BarcodeFormat.RSS_14,
BarcodeFormat.RSS_EXPANDED);
It is included in the list of 1D formats
ONE_D_FORMATS = EnumSet.of(BarcodeFormat.CODE_39,
BarcodeFormat.CODE_93,
BarcodeFormat.CODE_128,
BarcodeFormat.ITF,
BarcodeFormat.CODABAR);
ONE_D_FORMATS.addAll(PRODUCT_FORMATS);
changing your intent extra would enable ITF support, but might have other consequences (eg product search functionality)
I'm writing android application and my client requires a barcode scanner in it. They are really specific about it, so the layout they want is like this:
If a qr code found - it jumps to another window automatically. If manual pressed - you are asked to type manually and proceed with the rest of the app.
So basically I could embed zxing code to my app and add it to the activity but I don't want that and would like to have it as a separate app.
What I have at the moment is a separate activity called like this:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
I also tried this:
IntentIntegrator intentIntegrator = new IntentIntegrator(this);
Intent i = intentIntegrator.initiateCustomScan();
LocalActivityManager mgr = getLocalActivityManager();
Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;
if(wd != null) {
scanButton.addView(wd);
}
But then I get java.lang.SecurityException:
03-19 12:22:55.890: E/AndroidRuntime(29394): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.menucard.barcode.scan/com.barcode.scan.ScanActivity}: java.lang.SecurityException: Requesting code from com.google.zxing.client.android (with uid 10139) to be run in process com.menucard.barcode.scan (with uid 10169)
Maybe someone has an idea how to add a separate app into my activity? Or other ways to accomplish this?
You can't embed an external app in another app via Intent unfortunately. The external app here needs to take over the whole screen, and is in landscape mode, for starters.
You should write your own app, but can reuse parts of Barcode Scanner in your app so that it's not entirely from scratch. Just please don't copy the AndroidManifest.xml file. I think it will also be clearly not confused with Barcode Scanner given the different UI. All that remains is to make sure you follow the terms of the Apache License (easy).
#MindaugasSvirskas, your last comment is exactly what I was about to post now:-) I have faced the same problem in the past, in several apps, and believe me, just make use of Intents, that's the way the whole Android system is designed, favouring intercommunication between apps. iOS programmers can easily integrate the scanning Zxing layout in their own layouts, but we are supposed to make use of intents, and I agree.
first of all i will introduce myself. I am a young student from austria who is new to Android programming. My Project is to write a Barcode scanner and if you scan a product you get more information about it.
So lets get started with the real problem now:
I have done everything what the tutorials say and it works. The ZXING-Source Code is now a libary for my own Project and ofcourse it is included.
When i export the Android project as a FILENAME.APK and copy it to my SGS3 everything works.
Then i install the apk on my phone and start running the app. When i press the scan barcode button which calls the "onClick"-Method it does nothing. Android says to me the application has ben stopped.
I dont know which function i have to use. Should i use the IntentIntegrator methods or the intent methods to be able to scan a code. ( I know i cant use both in my Method, pasted it here to show your my problem )
public void onClick(final View view)
{
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}
this integration is provided by intents,so you had to have installed app which runs with specific intent (action=com.google.zxing.client.android.SCAN) like Barcode Scanner
i'm pretty sure that you don't have such app on your other phone and thats why you're getting "activity not found" Exception now
Edit: about diffs between IntentIntegrator and plain Intent ... well, there is no diffs beside that with IntentIntegrator you have it all nicely wrapped