Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Scanner takes time to open (QRcode) #601

Open
uzumakinaruto123 opened this issue Jan 23, 2018 · 11 comments
Open

Scanner takes time to open (QRcode) #601

uzumakinaruto123 opened this issue Jan 23, 2018 · 11 comments

Comments

@uzumakinaruto123
Copy link

Expected Behaviour

Scanner to open as soon as this.barcodeScanner.scan() is called.

Actual Behaviour

Currently, when this.barcodeScanner.scan() is called it lags/timesout for 3 to 4 seconds and thenopens the scanner.

Reproduce Scenario (including but not limited to)

Initially when my device was running on Android N (7.1.2) and project didn't had camera plugin, scanner use to open quickly.

I updated my device to oreo (8.0.0) after which I installed Camera plugin and now scanner opens slowly.

Either Android O(8.0.0) is the issue or camera plugin is.

Steps to Reproduce

  1. Start Ionic project
  2. Install Barcode cordova and ionic native plugin
  3. Call this.barcodeScanner.scan()

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 8.0.0

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Device: Xiaomi Mi A1

Cordova CLI version and cordova platform version

cordova : 7.1.0

Plugin version

phonegap-plugin-barcodescanner 7.0.0 "BarcodeScanner"

Sample Code that illustrates the problem

scanCode() {
    console.log('Scanning...I am called immediately.... but scanner will take time to open');
    if (this.platform.is('cordova')) {
      this.barcodeScanner.scan().then((barcodeData) => {
        // Success! Barcode data is here
        console.log(JSON.stringify(barcodeData));
      }, (err) => {
        // An error occurred
        console.log('Error is', err);
      });
    }
  }

Logs taken while reproducing problem

@macdonst
Copy link
Member

@uzumakinaruto123 I really doubt it is the camera plugin.

@uzumakinaruto123
Copy link
Author

Yes! Even I think the same. But, thought it was worth mentioning as these were major differences(oreo & camera) between first(slow) and second(fast) observation.

@saurabh-dk
Copy link

I have a Oreo (8.1) custom ROM installed on a three and half years old OnePlus One but I don't have any lag. Instead, I have an issue where if I press back on Scanning screen, instead of going back to previous screen, it exits the app.

@emir-drustinac
Copy link

emir-drustinac commented Jul 18, 2018

Im also having this problem. Every time when i call the scanner it starts with a few seconds delay (usualy about 3-5s). Here are my specs:

  1. Device: oneplus 5 running android 8.1 (performance is obviously not the problem here :) )
  2. My (cordova) app:
    cordova version: 8.0.0
    android platform 7.0.0
    installed plugins:
    cordova-plugin-clipboard-ka 1.0.0 "Clipboard"
    cordova-plugin-device 2.0.2 "Device"
    cordova-plugin-dialogs 2.0.1 "Notification"
    cordova-plugin-file 6.0.1 "File"
    cordova-plugin-keyboard 1.2.0 "Keyboard"
    cordova-plugin-whitelist 1.3.3 "Whitelist"
    phonegap-plugin-barcodescanner 8.0.0 "BarcodeScanner"

Could you guys @uzumakinaruto123 @macdonst @saurabhDuzumaki also write some more specs, so maybe we can figure out, what the problem is?

@emir-drustinac
Copy link

i tried it with cordova-plugin-camera 4.0.3 "Camera" and saw no differencies. The scanner still starts with a delay.

@emir-drustinac
Copy link

I've found the solution for my problem.
My App was configured to run only in portrait mode:
<preference name="orientation" value="portrait" /> (config.xml)
and i was calling the scanner with option: orientation: "landscape". I assume the problem was that the rotation is locked and the scanner starts in portrait mode (because the app is in that mode) and then immediately switches to landscape. This switching takes some time (its a bit laggy i would say) while scanner is running.
I measured time with Android Studio from the Cordova activity being stopped until the scanner activity is started:
Before the fix it was about 2,3 sec on my OP5, now its about 0,8 sec. All i did was, setting scanner option orientation: "" so that the scanner starts in the current orientation of the app. I think the scanner is even faster on devices with only 1 main camera (my OnePlus 5 has 2 rear cams), because i was seing some errors in android logs (something like "camera_0 couldnt be found...").

@Ross-Rawlins
Copy link

I have a client complaining about he start up speed and I have it set to portrait but tis still slow. IS there any other ways to speed this up or a way to keep the scanner open and pass that data to the app?

@oliverandersencox
Copy link

very slow on start up Iphone 7plus

@HamzaLJ
Copy link

HamzaLJ commented Aug 27, 2019

I'm facing the same issue too on iOS 12, iPhone X

@bfabbri
Copy link

bfabbri commented Oct 18, 2019

I'm facing a similar (but even more weird) issue. The camera on iOS only opens:
1 - after the app goes to foreground (I have to press home button and then touch the app icon to reopen it);
2 - after I open and close the notification center (swipe down from the top of the screen); or
3 - after I open and close the control center (swipe up from the bottom of the screen)

Has anyone faced this issue?

I think those situations cause iOS to trigger some event (but don't know which one) and then the camera is able to open.. maybe I could simulate this event?

@bfabbri
Copy link

bfabbri commented Oct 19, 2019

Guys, FYI I've just solved my camera opening problem adding "gap://ready file:;" to my Content-Security-Policy meta tag as suggested in #490

Now the camera opens as expected on iOS, but it takes around 1s to do so. I'll continue to work on that and I'll let you know if I find some way to shorten this time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

8 participants