I have a device that runs on android, the device has a trigger on it, when this trigger is pressed, the app should be able to catch this event and run some javascript, i have been wrecking my brain for a bit trying to figure out how to implement this flow. 

My java script for this is:

initialize() {
    this.platform.ready().then(() => {
      (<any>window).Scanner.init((success, err) => {

        (<any>window).Scanner.trigger((reason) => {
          if (reason == 0) {

Any ideas on how i could modify this script to an outystems friendly syntax that i can then invoke with the Javascript API?


Is this written in a specific Javascript framework? I'm not familiar with syntax like "(<any>window)". Can you shed some light on what this was originally used for? It might be easier to port functionality into your application rather than trying to port code.

From what you describe in your first paragraph, it looks like either a click action or capturing an event.

It is supposed to be capture an event whereby a trigger is pressed on a device and upon that action the app needs to open a native scanner of the device and scan a barcode. The device came with an SDK for android written in Java and i managed to build a cordova plugin and wrap it into outsystems and it works if you put an action on the screen, but i now need it to listen to the trigger button and then run the scan as opposed to a button on the screen.

When you say you've managed to build the Cordova plugin, does that mean you're already propagating the event to the Cordova Javascript context?

I've only needed to write a plugin once, but from what I gather of the process is:

 - Native code triggers an event using a CallbackContext object;

 - Cordova javascript receives that event and checks for registered handlers;

 - Cordova javascript triggers handlers;

The Barcode plugin for Outsystems looks like a good example:

How handlers are registered in the Cordova context and variables are passed to the Outsystems action:

How the native code triggers those events (https://github.com/tjwoon/csZBar/blob/master/android/ZBar.java):

What's going to change the most in your case will probably be the native code, since it's the most dependant on the SDK of the component you're using.