androidairandroid-activityflex-mobileair-native-extension

Zbar bar code native extension for AIR will not launch after home button takes focus away from application


Following the simple instructions for the qr-zbar, I have successfully implemented a native barcode scanner! It works great so far.

qr-zbar-ane Github: https://github.com/saumitrabhave/qr-zbar-ane

Unfortunately, while actively scanning, if the home button is pressed or another activity takes over, upon coming back to the original application the activity is stuck and will not initialize the bar code scanner anytime after that.

I have tried multiple ways of reloading and switching views in the air application to call a new instance of the qr-zbar.

Resetting:

scanner.removeEventListener(ScannerEvent.SCAN, onScan);
scanner.stop();
scanner.reset();
scanner = null;

Creating again:

scanner = new Scanner();
scanner.setTargetArea(targetArea,"0xF53100","0x4BFF33");
scanner.setConfig(Symbology.ALL,Config.ENABLE,1);
scanner.addEventListener(ScannerEvent.SCAN, onScan,false, 0, true);
scanner.launch(true, "back");                   
loadGroup.visible = false;
trace("Launched: " + ServerRequest.scanner.launched); 

Here is the Issue described in the commit notes! Exact problem.

https://github.com/saumitrabhave/qr-zbar-ane/blob/master/NativeAndroid/src/com/sbhave/nativeExtension/ui/CameraActivity.java

Update: I found that this is the case for a newer update to android. Downloading a keylogger for Galaxy S4 and Nexus 5, I'm unable to see the KeyEvent for a home button press.


Solution

  • Firstly apologies for such a long response time. Here is a point-wise update which will also answer your question (hopefully).

    1. The reason you see the code in repository but still issue not being fixed, its because I did not update the .ane which includes this fix. So, if you want to get it running with current APIs, you may need to checkout the project(at the last commit with old API) and re-compile/re-generate the ane on your end. I know, it doesnt sound interesting, read the next point for a good news (maybe).

    2. As you might have seen already the old model wasn't flexible enough, As it spawns its own Activity, Actionscript developer did not have any control over the UI in scanning mode. Hence I have re-designed the whole API in which the Scanner acts similar to a StageWebView(i.e. placed on top of the stage at given position and with given size so that you can have your own UI around it, with the limitation that you can not draw ON THE scanner).

      2.1 It also removes the notion of SingleScan or MultiScan and gives the developer flexibility to implement his own nature of scanning using APIs like pause(), resume(), attach and detach scanner while camera preview is in progress etc.

      2.2 It will also have other features like Scanning from a given Bitmap instead of Live Camera feed.

    Any of the option above should fix your issue, I would like to get suggessions/feedbacks/bugs as I am in the implementation phase,I can quickly resolve any valid use-cases you may have around the library.