Weird behaviour in Barcode Scanner (Android) - android

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.

Related

Barcode scanning broken

Since the recent update for Codename one any barcode scanning seems to be broken.
On android the camera appears and scans the code but nothing happens when it returns to the app (that is none of the 3 callback functions are triggered).
On iOS the camera window doesn't even appear.
I'm using this library since it doesn't rely on an installed scanning app:
https://github.com/littlemonkeyltd/QRScanner
I had thought the inbuilt scanning functionality may have been removed and passed to this library, so I tried to include that too:
https://github.com/codenameone/cn1-codescan
However it still isn't working on Android. IOS refuses to build with the cn1-codescan library included.
Pretty sure this was all working last week, or the week before.
my code looks like this:
Log.p("Scanning QR code");
QRScanner.scanQRCode(new ScanResult() {
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
Log.p("QR result:"+contents);
QRResult(contents, formatName, rawBytes);
}
public void scanCanceled() {
Log.p("scan canceled");
}
public void scanError(int errorCode, String message) {
Log.p("error during scan: " + message);
scanFailed();
}
});
edit:
Here are the android build hints added to codenameone_setting.properties when I add the libraries in:
codename1.arg.android.xapplication=<activity android\:name\="com.dm.zbar.android.scanner.ZBarScannerActivity" android\:screenOrientation\="landscape" android\:label\="#string/app_name" />
codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.CAMERA"/><uses-feature android\:name\="android.hardware.camera" android\:required\="false"/>
codename1.arg.android.proguardKeep=\ -keep class net.sourceforge.zbar.** {*;}
If you build against the "latest" barcode scanning should work. I'm assuming that you built against 3.5 and not the latest. It's possible that the regression in barcode scanning got into 3.5, this we verified that barcode/qr code scanning works with the latest on the build servers.

How correctly manage the First ZXING Intent? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have implemented the ZXing functionnality in my App to read QR-Code.
Xzing runs with Barcode scanner via an exmplicit intent so the first you initiate the intent, it will ask to install barcode.
So it redirect you to the Play Store and the application gets installed.
Anyway, there is something not really easy to manage here as the Intent has been launched but we never get a return.
So the application waits for ever....
Is there any event to intercept or something like that...
Maybe there an OnActivity result for barcode installation already in the Integrator?
I tried to first deal with the PackageManager according to what is said here Zxing via intent
But in fact the test list.size() is successfull for ... Zalando Arghhh!!!
What happens?
The goal was to check if BarCode is installed, if no, ask for install it with a StartActivityForResult and once the install is complete, launch the Scan Intent.
Regards,
So,
It's a pity I don't have an answer to my question because I wonder in fact if it's no more common than only using Xzing.
The actual prefered Xzing implementation seems to be to use an intent to launch the barCode Scanner application.
The problem occurs if BarCode Scanner is not yet installed on your device.
In that case, the intent launch the play store to let you download it.
Here is the problem because, unless I didn't understand something and as I didn't get an answer, I think I'm not wrong, once BarCode Scanner is downloaded, installed and launched, you don't receive any answer to your sent Intent! Letting your user the ass between two chairs.
Another alternative could be to deal first with the package manager to ask it if Barcode Scanner is installed. That way, you discuss with the package manager to install the app and then launch your scan intent.
Unfortunately, I also tried that but for a reason I didn't understand asking to the package manager if "com.google.zxing.client.android.SCAN" is present gives a positive answer for ... Zalando !?! Arghhh!
Other possibility should be to integrate pieces of Xzing directly in your app.
I read many posts on this subject, all based on a different Xzing version and giving different methods and I didn't succed to get a working solution.
And obviously again, it seems that sean Owen clearly discourage this solution. What I really don't understand because in some situation, having to download a third party application while you are using your app could be vey uncomfortable and doesn't improve user experience. Well that's my point of view. I assume it even if it caused a serious downgrade in Stackoverflow !!
That's said my answer is to used Zbar. Zbar is no longer maintained on Android because its developper switched to Xzing!! well....
Anyway, it's an extremely efficient and eazy to use library and especially for the last reason, it's a high quality product.
Here I explain how to implement it:
-First download the archive https://sourceforge.net/projects/zbar/files/AndroidSDK/ZBarAndroidSDK-0.1.zip
-Then extract it of course.
You will get various directories:
*examples, with a CameraTest activity I encourage you to integrate in Eclipse to test it and also because your will get its components
*libs wher you will find the subdirs x86, armeab-v7a, armeabi and zbar.jar library.
Once you have imported cameraTest project in Eclipse, you should have a fully working code scanner named CameraTestActivity.
So to integrate the functionnality in your application follow these steps:
All required components are in CameraTestActivirty of course.
Copy/paste CameraTestActivity.java and CameraPreview.java from CameraTestActivity src to your proper src directory.
You would prefer to Copy/Paste the package, as you prefer.
Personnally, I renamed CameraTestActivity to QRCodeScanActivity
Copy/Paste all directoris in libs from CameraTestActivity to you proper libs directory.
Include the following part of AndroidManifest.xml in your proper AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" /> Here it's as you want, it should work also on non autofocus devices
... your already present declarations....
....
Copy/Paste the main.xml from layout i CameraTestActivity to your proper layout directory. CameraTestActivity will force portrait orientation during the scan.
Rename this file as you want; qrcodescan.xml if you want.
You have to declare that you use zbar.jar library.
Right-click on yout application name, select properties, click on Java Build Path, then click on Add JARs and go through yourAppName\libs to select zbar.jar.
You have to change 2 or 3 little things in the code.
In QRCodeScanActivity, previously CameraTest Activity:
public class QRCodeScanActivity extends Activity {
// declare a constant to use in the Intent created in your application to start he scan.
public final static int ACTIVITY_SCAN_CODE = 33;
.....
// Declare an intent to respond to your activity
Intent activityResult = new Intent();
// Not mandatory, you can add an intermediate String to return to your application
String textScanned;
......
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Put here the name you choosed in place of main.xml
setContentView(R.layout.qrcodescan);
....
// Later you will choose if you let the TextView and the Button or not. Personnaly, I removed it to just keep the test if (barcodescanned) and its content.
scanText = (TextView)findViewById(R.id.scanText);
scanButton = (Button)findViewById(R.id.ScanButton);
scanButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (barcodeScanned) {
barcodeScanned = false;
scanText.setText("Scanning...");
mCamera.setPreviewCallback(previewCb);
mCamera.startPreview();
previewing = true;
mCamera.autoFocus(autoFocusCB);
}
}
});
}
public void onPause() {
super.onPause();
releaseCamera();
}
...............
PreviewCallback previewCb = new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms) {
scanText.setText("barcode result " + sym.getData());
barcodeScanned = true;
// Here is what you have to add to return the result to your application
textScanned = sym.getData();
activityResult.putExtra("SCANNED", textScanned);
setResult(RESULT_OK, activityResult);
finish();
}
}
}
};
// Mimic continuous auto-focusing
AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
autoFocusHandler.postDelayed(doAutoFocus, 1000);
}
};
}
In your application now:
Somewhere where you want to start the scan from; add:
Intent intent = new Intent(this, QRCodeScanActivity.class);
startActivityForResult(intent, QRCodeScanActivity.ACTIVITY_SCAN_CODE);
and you should have the necessary code to receive the result:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == QRCodeScanActivity.ACTIVITY_SCAN_CODE) {
String textScanned = intent.getStringExtra("SCANNED");
....
}
}
That should work vey very well.
Regards,

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

Android / ZXing no longer works

my app makes use of ZXing barcode scanner using the ZXing helper classes IntentIntegrator and IntentResult.
Now I found there are no longer scanning results submitted from ZXing, the related return values are empty/null.
Thus I updated to latest helper classes http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentIntegrator.java and http://code.google.com/p/zxing/source/browse/trunk/android-integration/src/com/google/zxing/integration/android/IntentResult.java
Now my onActivityResult method is called immediately after ZXing is started - of course with an empty result again.
My code is quite simple, scanning is started this way:
if (v==scanButton)
{
com.google.zxing.integration.android.IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
}
and fetching the results this way:
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
com.google.zxing.integration.android.IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null)
{
String format;
format=scanResult.getFormatName();
if ((format!=null) && (format.length()>0))
{
if ((format.equals("EAN_8")) || (format.equals("EAN_13")) ||(format.equals("UPC_A")) ||(format.equals("UPC_E")))
getEANData(scanResult.getContents());
}
}
}
On my android the latest ZXing code is installed. Any ideas why it does not work any more?
From what I found out meanwhile: this seems to be an installation-dependent problem. On my Android device I can see that problem but it is not reproducible, other users of my App do not experience this. ZXing code itself wasn't changed for longer time and there users confirm it works too - so that seems to be a really ugly bug.
Here it happens with ZXing-code installed from Playstore, haven't tested it with ZXing included into my app yet...

Zxing 1.7 And Android API 15 -Scanner Crashing the App on Motorola device

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

Categories

Resources