Cordova plugin error: Cannot read proprty 'flashlight' of undefined

Cordova plugin error: Cannot read proprty 'flashlight' of undefined

  

Hello,

I'm learning new version P10 and trying to implement example from video lesson "Plugins" http://www.outsystems.com/learn/lesson/801/plugins/

But I got Cordova plugin error: Cannot read property 'flashlight' of undefined

I have created apk-file and installed it in android device. Error still appears but a little bit different

What I made incorrect when implemented "Plugins" lesson? 

Best regards,

Victor

Hi Victor,

Cordova plugins only work in the device (not in the browser). Symptom you saw in the first image is expected.

Did you generated and installed on the device a new mobile app build after you introduced the plugin?

João Neves wrote:

Hi Victor,

Cordova plugins only work in the device (not in the browser). Symptom you saw in the first image is expected.

Did you generated and installed on the device a new mobile app build after you introduced the plugin?

Hello João,

Yes. I have generated and installed on the device. Please read my post. After first picture I added second picture of my device with error.


Hi Vitor,

What João is asking is if you installed the app for Android after adding the Cordova plugin or before?

It sometimes helps if you just remove the app from your phone and install again when the Cordova plugin was added in a later stadium.

Could you try to remove & install the app on your Android phone again?

Kind regards,

Remco Dekkinga

Remco Dekkinga wrote:

Hi Vitor,

What João is asking is if you installed the app for Android after adding the Cordova plugin or before?

It sometimes helps if you just remove the app from your phone and install again when the Cordova plugin was added in a later stadium.

Could you try to remove & install the app on your Android phone again?

Kind regards,

Remco Dekkinga

Sorry I didn't understand João's answer correct. 

I installed application on the device after I added Cordova plugin. At the first I tested everything in web and then installed on device.

As you recommended I uninstalled ToDo_VM application 


and install it again from  ToDo_VM.apk


But error still the same like in my first post on second picture


Hi Victor,

Here's a possible hint. It might be that the plugin doesn't support your device or your device's OS version. So you should actually first check if the capability is available before calling the switchOn function.

Looking into the lesson code I don't see this code - the guys must have kept it simple as it works with most devices and OS versions.

What you need to do is to create another Client Action in the logic tab to check this, call it IsAvailable. This action returns a boolean parameter.

In the action flow add a javascript node with an output parameter also boolean, e.g. available. Then use this code:

Don't forget to assign the output of the javascript node to the output parameter of the client action.

Now in the SwitchOn and SwitchOff use this action to test if the capability is there:

I hope this helps.

Cheers

Thank you André for your response.

I made changes like you wrote. At the first I have created new Action name isAvailable

Then I lunch this action from application

Then I uninstall previous version of ToDO_VM application from device, prepared new ToDO_VM.apk and installed it on device. 

When I started application and pressed button "Flashlight On" I got below error. This mean that function "available" cannot started.

All testing I made in follow android device. Asus P002 android version 5.1.1.


Could you write what Android version I can use for Cordova plugin?

Best regards,

Victor



Hi Victor,


What do you mean by "prepared a new APK"? Did you generate the app again like below?

Can you share the plugin and your app so that I can have a look at it? It might be the case that the plugin isn't actually been bundled with your app...

Hello André,

Preparing ToDO_VM.apk step 1

Press tab "Native platform', then press button "Generate App" 

Preparing ToDO_VM.apk step 2 

Wait while indicator go to end

Preparing ToDO_VM.apk step 3

Press link "click here to copy the installation link" to copy URL

Preparing ToDO_VM.apk step 4

Paste URL from previous step, then press button "Get for"

Then I download ToDO_VM.apk, copy it to my device, uninstall previousversion and install new.

Is it correct steps to prepare ToDO_VM.apk?

Could you write what Android version I can use for Cordova plugin?

End goal of my experiments with Cordova plugin is creating new version of application to refund VAT. Current version based on Outsystms version 9 and work with USB passport scanner and Bluetooth printer to print receipts. Now all of this functionality implemented in Java-application in Android Studio.
Is it possible to create the same functionality using Cordova plugin? 

Best regards,

Victor


Hi Victor,

Yes, that this the correct way to generate a new app.

Regarding Android version, it really depends on the plugin you need to check the documentation on Git for that specific plugin.

I think that all that functionality will probably be implemented with more than one plugin. There's already in the forge plugins that allow you to scan documents and certainly, you'll find plugins for Bluetooth printing.

Regarding the problem you are having, I suggest you share the modules for us to understand what might be the problem that results in the plugin not being bundled in the app.

Cheers


Hello André,

I attached all oml files. See below

ToDo_Core_VM.oml

CordovaPluginHello.oml

FlashlightPhoneGapPlugin.oml

ToDo_VM.oml

Hello Victor.

Can you provide a screenshot of what it looks like when you're in the "Develop" Tab (the one on the left of "Native Platforms"? Do you have all the above modules in one single application?

Example


Thanks

Hello César,

I have two applications for testing mobile phone in P10. 

First is ToDo_VM (only with mobile application module) and second CordovaPluginMobile contains only Cordova plugin modules

If you want you can open my sandbox

Environment: medvedevvictor.outsystemscloud.com

Username: medvedev_victor@mail.ru

Password I sent you as private message


Best regards,

Victor

Hello Victor.

The issue is that you have everything in one single application (and not as a references). You should have your main application and create another application with just the FlashlightPhoneGapPlugin (take a look at this answer: Architecture your app)

In your case, you should:

1) Create your application with all the modules you need. Make sure the main module of your application is set as homemodule.

2) Create a plugin with the logic to interact with device capabilities. Make sure you have the main module set as homemodule. If the module is bold and you see "Unset as Home", than it's correct. If it's not bold and you see "Set as Home", click it.

3) In your CordovaPluginMobile application, reference the public actions from the FlashlightPhoneGapPlugin.

4) Generate the CordovaPluginMobile mobile application again in order for the service to pack your new plugin.

Let me know if you need any more help.

Thanks