Phonegap-plugin-barcodescanner: Flashlight option

Created on 1 Dec 2016  路  9Comments  路  Source: phonegap/phonegap-plugin-barcodescanner

I have been asked to build a simple barcodescanner app, so I stumbled on this plugin. Let me first say: Everything Eddy makes, works like a charm!

My client asked to have the flashlight on when scanning, so I started using this plugin: https://www.npmjs.com/package/cordova-plugin-flashlight in combination with this plugin: https://github.com/MangoTools/cordova-plugin-lightSensor

Separately from on another the plugins work great, but I can't seem to combine them and have the flashlight on when the scanner is active. Is this even possible?

enhancement help wanted

All 9 comments

@vespino Thanks, but I'm one of many contributors to this plugin. I'm gladly sharing your kind kudos with all others.

This plugin can't cooperate with flashlight plugins as Android doesn't permit it, but you can use the volume up/down buttons to toggle the flashlight on Android while scanning through this plugin. It would be possible to extend the code to pass in a preference which enables the flashlight by default, and do the same on iOS but it's not something I'm planning on doing.

@EddyVerbruggen strange that Android doesn't permit it, I have an app that does allow the flashlight to be turned on using a button on the screen. What you are saying is that Android doesn't allow it to be turned on automatically, correct? What about iOS, does it allow both to be operated at the same time?

Unfortunately I'm not capable of changing the native code, so I have to work with plugins as the are. What do you mean by "but you can use the volume up/down buttons"? Do I have to press the button, or can it be done programmatically?

Anyone willing to take a shot at writing the addon? I'm willing to pay a small amount of money and think more people will benefit from this.

While the scanner is open using this plugin you can use the volume up/down buttons to control the flash. But AFAIK you can't enable the flash using another plugin _before_ opening the scanner.

If that suits your needs than a piece of code like this is required to enable the torch on iOS and it could be wired-up from the volume controls as well as shown elsewhere in that NativeScript sourcecode.

@EddyVerbruggen since you said "before", I have tried "after" but without success. The only thing that seems to work is the physical volume up button. I'm looking for a solution for both Android and iOS btw.

@EddyVerbruggen something that just crossed my mind: would it be possible to launch the barcodescanner with some room at the bottom so I can place a flash button?

Hey @vespino, can you give 6.0.4 a spin? Pass in showTorchButton : true as one of the scan options and you should see a torch button while scanning. Please reopen if anything is wrong.

Great job @EddyVerbruggen ! Works like a charm ! I'm only able to test this on Android for now, so maybe I'll get back to you on iOS. Thanks for now.

@EddyVerbruggen confirming - flash & camera flip works for me on android(4/6)(header icon buttons) & ios 10 ( footer bar) w.r.t - ver 6.0.5-dev

This thread has been automatically locked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ishanjain2801 picture ishanjain2801  路  3Comments

front-stream picture front-stream  路  7Comments

HallmediaDigital picture HallmediaDigital  路  4Comments

Bajranghudda1 picture Bajranghudda1  路  4Comments

camilonos77 picture camilonos77  路  7Comments