Zxing ITF barcode not scanning in custom app - android

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)

Related

ZXing PDF417 + ALL_CODE_TYPES

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.

Embed zxing barcode scanner to the activity

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.

Zxing - My app does not want to start the camera

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

Is there a way to add reminders to a new calendar event using Intents?

I need to support Android 2.1 and up. I know that CalendarContract isn't available in Android 2.1, so I've done the following workaround.
Intent intent = new Intent(Intent.ACTION_EDIT)
.setType("vnd.android.cursor.item/event")
.putExtra("beginTime", beginTime.getTimeInMillis())
.putExtra("title", title)
.putExtra("description", description)
.putExtra("eventLocation", location)
.putExtra("allDay", allDay)
.putExtra(Intent.EXTRA_EMAIL, email );
if(!allDay) {
intent.putExtra("endTime", endTime.getTimeInMillis());
}
startActivity(intent);
This works very well so far. I've tested on 2.1 through 4.1.
I'd like to add reminders, too, but I can't find any documentation on how to do it using Intents. Does anyone have an example? I want to avoid adding more permissions to my manifest for writing to the calendar, so if you have a suggestion that requires that, I won't be able to use it.
If you check the stock android Calendar source code, reminders cannot be added using intent.
Instead of this calendar has a setting to set the default reminder. But some OEMs could have implemented this. So even if you find it, it will not work on all phones.

RecognizerIntent not working; "missing extra calling_package"

I'm having problems using the RecognizerIntent API on Android 2.2. When I call the API using this code:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
startActivityForResult(intent, REQUEST_CODE_VOICE_SEARCH);
which looks like it should work, the search popup says "Unknown problem" on the device and in the logs it states:
01-17 14:25:30.433: ERROR/RecognitionActivity(9118): ACTION_RECOGNIZE_SPEECH intent called incorrectly. Maybe you called startActivity, but you should have called startActivityForResult (or otherwise included a pending intent).
01-17 14:25:30.433: INFO/RecognitionControllerImpl(9118): startRecognition(#Intent;action=android.speech.action.RECOGNIZE_SPEECH;launchFlags=0x800000;component=com.google.android.voicesearch/.IntentApiActivity;B.fullRecognitionResultsRequest=true;S.android.speech.extra.LANGUAGE_MODEL=free_form;end)
01-17 14:25:30.433: INFO/RecognitionControllerImpl(9118): State change: STARTING -> STARTING
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): required extra 'calling_package' missing in voice search intent
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): ERROR_CLIENT
01-17 14:25:30.443: ERROR/RecognitionControllerImpl(9118): ERROR_CLIENT
It looks like the problem is the missing "calling_package" extra; on the RecognizerIntent page it states that this extra is:
The extra key used in an intent to the speech recognizer for voice
search. Not generally to be used by
developers. The system search dialog
uses this, for example, to set a
calling package for identification by
a voice search API. If this extra is
set by anyone but the system process,
it should be overridden by the voice
search implementation.
As far as I can tell, I don't need to override this extra, so why am I getting this error? How can I fix my code?
I had the exact same problem. I was working on existing code that had android:launchMode="singleInstance" in the activity I was working on. This will not work for speechrecognizer intent. I changed it to android:launchMode="standard". Now let's see how it breaks the rest of my program :)
Your original code:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
startActivityForResult(intent, REQUEST_CODE_VOICE_SEARCH);
Works correctly. I tested it on my device (HTC Desire), and also compared it to other open-source uses, by executing the following query in Google, and browsing the source code.
RecognizerIntent.ACTION_RECOGNIZE_SPEECH
site:code.google.com
One of the output lines in my logcat looks like this:
01-26 13:28:53.268: INFO/RecognitionController(1459): startRecognition(#Intent;action=android.speech.action.RECOGNIZE_SPEECH;component=com.google.android.voicesearch/.IntentApiActivity;B.fullRecognitionResultsRequest=true;S.android.speech.extra.LANGUAGE_MODEL=web_search;S.calling_package=com.test;end)
Run a similar search with one of the built in apps (or downloaded ones), see that it works (and is not a device issue, etc.).
If that works correctly, take the code to a new test project, simply put those lines in the onCreate (Change the result constant to 0), and see if it works.
Have you tried setting the extra yourself?
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
intent.putExtra("calling_package","com.yourpackagename.YourActivityClassName");
startActivityForResult(intent, REQUEST_CODE_VOICE_SEARCH);
This is the approach used by this code and is the suggested solution to a similar issue.

Categories

Resources