How correctly manage the First ZXING Intent? [closed] - android

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,

Related

ZXing QR reader library for Android reading painfully slow

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.

ZXing android use front camera

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

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.

Weird behaviour in Barcode Scanner (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.

Accessing front camera of mobile using flash?

Recently I went thru the code for accessing the camera using flash ActionScript3 and I have tested the code in iMac machine, iPhone and Android.Now based on this, I am developing an application for Android which includes the accessibility of the front camera. Now my Problem is I dont know how to access the front camera? We should use some other code or should we specify which camera should be accessed? First of all, can we access the front camera thru flash?
I made a simple android app. Here is the code for selecting camera window
public class SelectCameraAlertAndroid extends StartAlertAndroid_design{
public function SelectCameraAlertAndroid() {
frontCameraButton.addEventListener(MouseEvent.CLICK, onFrontCamera);
backCameraButton.addEventListener(MouseEvent.CLICK, onBackCamera);
}
private function onFrontCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("1");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
private function onBackCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("0");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
}
Not true. You can access the front camera on Android.
The only problem is that you don't get to use the CameraUI(pretty sure).
var camera = Camera.getCamera("1");
camera.setMode(stage.stageWidth, stage.stageHeight, 30, true);
var video:Video = new Video(stage.stageWidth, stage.stageHeight);
video.attachCamera(camera);
addChild(video);
Note: This answer is outdated. Please refer to the other answers for updated information.
Currently, AIR only supports access to the primary camera on an Android device.
http://forums.adobe.com/thread/849983
Official documentation: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
"On Android devices, you can only access the rear-facing camera."

Categories

Resources