hypery2k / cordova-barcodescanner-plugin

barcode scanner plugin for PhoneGap
51 stars 39 forks source link

Barcode scanning cancelled on Android 4.1 #3

Closed andersborgabiro closed 8 years ago

andersborgabiro commented 8 years ago

When I scan any barcode, seemingly successfully, it always returns success/cancelled with no data. It works fine on Android 5.x.

andersborgabiro commented 8 years ago

Just wanted to know whether you could replicate, as I'm planning a release of my app.

hypery2k commented 8 years ago

currently I cannot reproduce due to not having any Android 4.1 devices. Sorry to say

andersborgabiro commented 8 years ago

I tried with todays's build, after some changes, and it behaves the same. This is the core code in my app. The exact version is 4.1.2. I see no warnings or errors when running ddms/monitor.

    var scanner = cordova.require("cordova/plugin/BarcodeScanner");
    scanner.scan(
            function(result) {
                if (!result.cancelled) {
                    var data = fixData(result.format, result.text);
                    addHistory(data);
                    actOnData(data);
                }
            },
            function(error) {
                alert("Barcode reading failed: " + error);
            }
    );
hypery2k commented 8 years ago

I've got now idea why the callback is not happening, you try if it works with this plugin: https://github.com/Telerik-Verified-Plugins/BarcodeScanner

andersborgabiro commented 8 years ago

I'm using PhoneGap Build, so I'm not too eager to build locally. Is it available on npm as well?

andersborgabiro commented 8 years ago

telerik-barcode-scanner doesn't work either ({"cancelled": true, "text": "", "format": ""}), if that was the plugin you meant.

It also has the disadvantage of forcing the app name to be "Barcode Scanner", whatever it might be set to in config.xml.

Also, the image is distorted (incorrect aspect ratio).

Anders

andersborgabiro commented 8 years ago

I tried with all variants of this plugin that I could find, and I get "cancelled" on all of them. Instructions indicate I should write like this, so that's what I do now (iow, no include): cordova.plugins.barcodeScanner.scan(...

I only have access to Android 4.1 and 5.1 at the moment, so I can't tell where the break is.

Considering it suddenly broke for all plugins I suspect the switch to cli-5.2.0. Going back to 3.7.0 doesn't sound like a good idea though.

Anything I can provide to make bug finding easier?

Cheers, Anders

andersborgabiro commented 8 years ago

I noted that the "Success but cancelled" event is issued when barcode scanning is started (when the call is made to scan), not when it's finished. There's no event issued when finished on Android 4.1. There's no Javascript error issued either, so it's inside the plugin somewhere.

Not much more I can do I'm afraid. I have worked with Zxing in the past (for native Android), but not PhoneGap plugins, so it would be better if someone else checked it out.

andersborgabiro commented 8 years ago

Any attempt to fix this yet? Sorry for nagging.

hypery2k commented 8 years ago

Sorry to say but I cannot reproduce the error

andersborgabiro commented 8 years ago

I believe I've found the reason, and somehow I can understand why it fails, but only slightly:

On Android 4.1 (at least), this causes the behavior: `

</gap:config-file>`

I guess the plugin needs to "kick" CaptureActivity but it fails due to this setting, yet oddly it works on 5.x.

I've removed it now (it was there due to a "copy-paste"), and will publish a new version promptly.

1.20 will soon be available here: https://play.google.com/store/apps/details?id=com.abiro.phonegap.cliqtagsqr

Thanks for your attention and patience, Anders

carlosbc84 commented 8 years ago

Hi everyone,

I'm having the same problem on android 4.2.2. I'm compiling with cordova 5.4.1 and change the preference AndroidLaunchMode on config.xml with all its possible values. Still no work.

Can anyone give me a clue?

Thanks.

hypery2k commented 8 years ago

As I'm not having any Android 4.x device anymore I can not verify the behavior

andersborgabiro commented 8 years ago

@carlosbc84: My solution was to remove android:LaunchMode entirely. Did you try that?

carlosbc84 commented 8 years ago

@andersborgabiro Yes, I remove android:LaunchMode from config.xml file. Is there another way to do this?

UPDATE: I've noticed that even when I remove the AndroidLaunchMode from config.xml Cordova output maintain the tag in the AndroidManifest.xml with value singleTop. Is there a bug of Cordova (latest version)?

Thanks for your response.

bill-rousseau commented 8 years ago

@andersborgabiro Hello, I've experienced the exact same problem on an Ionic app. I've tested it on Android 4.4.2 devices and several previous Android devices, with no success. I can't figure out where to delete android:LaunchMode. I mean, I've found it in several Manifests in plugin or in platform folder, but it keeps on re-editing the files and putting it back when building. I took a look at your CliqTags app which seems to work well, so I wondered if you had got new hints on that issue?

andersborgabiro commented 8 years ago

I use PhoneGap Build, so it might be different there. I removed it from config.xml.

I do need it set to single instance in my Beacon Reader, so it doesn't relaunch when the user acts on a local notification. This in turn caused the issue in QR Code Reader due to copy-paste.

In Beacon Reader config.xml: `

</gap:config-file>`

I can post the config.xml if you like.

bill-rousseau commented 8 years ago

Actually I cannot find such an XML component anywhere in my project. Perhaps that's a Phonegap-builded syntax, but anyway, the only thing I've got which looks alike this is : <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize"> in app/platforms/android/AndroidManifest.xml. And a JS function in some config file, but I think I don't want to change it...

andersborgabiro commented 8 years ago

PhoneGap, Cordova and PhoneGap Build all use config.xml, and it's configures manually.

There's a config.xml in the root of an Ionic project, but it's very different from what I use for PGB.

As Ionic uses Cordova, maybe you could insert a LaunchMode statement in your config.xml. Whether it would override the singleTop setting is unknown.

bill-rousseau commented 8 years ago

<gap:config-file parent="/manifest/application" platform="android"> <activity android:launchMode="singleInstance" /> </gap:config-file>

What does the "parent" refer to? I could try to add this in config.xml, but I can't guarantee.

andersborgabiro commented 8 years ago

It's the manifest sub tag where this should be added, making it a generic solution for setting such options.

But as Ionic uses Cordova, I'm not sure gap: tags will work. Otherwise maybe the Ionic team can help you.

An option is to use a different barcode plugin, e.g. org.madmobile.cordovaplugins.zbarscanner.

bill-rousseau commented 8 years ago

I think this might be what we're talking about: http://pastebin.com/eZvymquF

plugins/phonegap-plugin-barcodescanner/plugin.xml

In that file, the second component config-file (which I show you in that pastebin) contains an attribute android:name="com.google.zxing.client.android.CaptureActivity". If I get your drift well:

I guess the plugin needs to "kick" CaptureActivity but it fails due to this setting, yet oddly it works on 5.x. I've removed it now (it was there due to a "copy-paste"), and will publish a new version promptly.

I should delete that attribute. I did, and I added the attribute android:launchMode="singleInstance", as you can see in the file I joined. I builded after that but it still has not changed my barcode scanner bevahior.

andersborgabiro commented 8 years ago

CaptureActivity must be there. That's how Zxing is constructed.

By removing LaunchMode I essentially reverted it to "standard", which made it work. "singleInstance" stopped the activity from launching. That's how I interpreted it anyway.

See android:LaunchMode: http://developer.android.com/guide/topics/manifest/activity-element.html

As I don't use Ionic I can't help you with anything specific to that.

bill-rousseau commented 8 years ago

LaunchMode wasn't present in the first place actually. So I think "removing" it will not make it work.But I will see more by this side, thanks.

andersborgabiro commented 8 years ago

I was referring to my code, where it was present.

PaulCannell commented 8 years ago

Has anyone managed to solve this. Im running android 4.4.2 and still having this problem. Thing is 3 weeks ago it all worked perfectly, same app same phone. I did however remove and readd the android project. Ive tried cordova 5.2 and 6 and same outcome

andersborgabiro commented 8 years ago

To test, I rebuilt (via PhoneGap Build) with latest everything and it works fine on 4.1 and 5.1 at least.

cli-6.0.0 (4.0.1 / 5.1.0 / 4.3.0)

cordova-plugin-appversion npm * 1.0.0 n/a android,ios,winphone cordova-plugin-barcodescanner npm * 0.7.0 n/a android,ios,winphone cordova-plugin-device npm * 1.1.1 n/a android,ios,winphone cordova-plugin-dialogs npm * 1.2.0 n/a android,ios,winphone cordova-plugin-inappbrowser npm * 1.3.0 n/a android,ios,winphone cordova-plugin-statusbar npm * 2.1.1 n/a android,ios,winphone cordova-plugin-whitelist npm * 1.2.1 n/a android,ios,winphone cordova-plugin-x-toast npm * 2.4.2 n/a android,ios,winphone

PaulCannell commented 8 years ago

So after a sense of humor melt down I created a new empty ionic project and added the scanner. Works 100%. Move back to the existing project still doesnt work. Tried removing and adding platform still doesnt work. Id love to get to the bottom of this but I fear sanity may be the next thing to break. Sorry I have nothing more concrete to contribute.

andersborgabiro commented 8 years ago

Did you try the classical "remove plugins until it works" method?

PaulCannell commented 8 years ago

I did that a no of times. The the app is android only tried adding and removing IOS. LIke I said eventually started an empty project from scratch and copied over the contents of the previous WWW folder. Hope that helps someone :)

hypery2k commented 8 years ago

for me on my two test devices and the emulator it's working so far with only this plugin added. So I will lock this issue as it's focused on a dedicated plugin error