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
Related
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.
I have Zxing 1.7 and Android api 15. Integrated the scanner through Intent and added CaptureActivity so that application does not ask for which camera to use.Created core.jar and added it in Android project lib and added Zxing Android as library project to my project build path.
The scanner does not work and application crashes first time when i click on "san" tab of my app but next time the same functionality it works when i login back in my app and barcode can be scanned.
When the application crashes for first time it give ClassNot Found exception for CaptureActivity . I have followed all the requires steps and also added CaptureActivity in the Manifst.xml file.
Please advice as i have tried lots of alternatives. Does Zxing works only with Android API9 that is made obsolete now and its replacement is 10? Below is code for my ScanActivity
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//Scan code
Intent intent= new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
//To aviod the complete action using dialog box
intent.setClassName(this, "com.google.zxing.client.android.CaptureActivity");
startActivityForResult( intent, 0 );
//getApplicationContext().startActivity( intent );
//View scanView = ((ActivityGroup) context).getLocalActivityManager().startActivity(id, newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
/*
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage( "com.google.zxing.client.android.SCAN" );
i.addCategory( Intent.CATEGORY_LAUNCHER );
startActivityForResult( i, 0);
*/
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
System.out.println("ScanRewardCodeActivity OnActivityResult Method");
if(requestCode == 0)
{
//Stop QR Code Reader intent
finishActivity( 0 );
TabActivity tabActivity = (TabActivity)getParent();
TabHost tabHost = tabActivity.getTabHost();
if(resultCode == RESULT_OK){
System.out.println("Done");
}
}
}
There are a number of problems here.
If you are using Intents, you do not need core/ or android/ code. Make sure to remove all of this code from your project as I think it is interfering and causing the crash.
You should not modify your AndroidManifest.xml
Yes zxing 1.7 works with all versions through to 4.0.x, but, you should use zxing 2.0 which was released a few days ago
Don't try to write your own integration code. Use the code given in android-integration/ as it definitely works
I am developing an Android application and I am currently having some troubles running Barcode Scanner (Zxing). I'm using Zxing as a "library project" in Eclipse.
I built Zxing core project with Ant, created my Zxing android project by importing sources in Eclipse and ticking the "Is Library" box. (That project uses the "core.jar" in its dependencies.)
Then I have my main project, which uses the Zxing library project, that project, uses the "core.jar" too.
So, here is the problem, when I run my application and start my Barcode Scanner Intent,
here is what I see on the screen :
http://imageshack.us/photo/my-images/52/screenbarcodescanner.png/
(I am sorry but I don't have enough reputation to post my screen here)
The strange thing is that it seems to recognize some things when I put my hand in front of the camera or some barcode, QR Code (it doesn't scan, but there are some green dots appearing on the red line, you know, it is a bit hard to aim the code without seeing anything on the screen ;) )
Finally, here is the way I am calling the Intent and managing the result, the basic way, as it is written on the Zxing Google code page :
#Override
public void onClick(View sender)
{
if(sender.equals(_scan_button))
{
startActivityForResult(new Intent("com.google.zxing.client.android.SCAN"), 0);
}
// ...
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
//String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// ...handle the result
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
I don't actually provide the code format to the Intent because I want it to scan any code format.
Last thing I can say, is that, before doing this with Zxing as a library project, I was using just as a "project dependency", that way, Zxing apk was installed on my phone if not installed, before running the main project. All was working very well, now it is embedded,...I'm stuck and I don't really why or what I am missing.
Thank you for your answers !
You're mixed up here. If you integrate by Intent, you do not need any code from Barcode Scanner. In the project, all you may need is the small bit of integration code you find in android-integration. This ought to solve your problem.
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.