Plugins
Plugins
This lesson is part of the Developing OutSystems Mobile Apps course.
LEARN MORE

Transcript
Welcome to the plugin session. In this session we would like to discuss what
plugins are and the Apache Cordova framework that those plugins live in.
Discuss which of those plugins are the common plugins that are included by
default inside of the shell, and what other types of available plugins are available
for downloading from the forge.
There also is the capability for creating a brand new plugin inside
of OutSystems and we'll talk about the steps to create a reusable plugin
module. So let's get started on the Cordova plugin section so what is
Apache Cordova? It's an open-source mobile development framework, that allows
the use of standard web technologies for cross-platform development. So basically
by using HTML 5, CSS 3 and JavaScript it has the ability of generating the code
necessary for the native platform, so given descriptions of that type of
information which is sort of standard web stuff you would be able to use the
framework and generate the XCode for Apple or the Android in the Java code
that you might need to be able to do that. So what are the plugins? The plugins are
the code that's going to provide the interface between cordova and the actual
native component. So cordova has the ability to go ahead and bind and
communicate to the devices and its components, and then javascript can
interact with the native code to be able to control and work all that. So the
cordova framework has been around for quite a while, and it has this
ability for us to define the web app and what we want things to look like and the
rendering engine will go ahead and
render that for the device. So the mobile operating system will have different
input capabilities, graphic sensors and services, and the cordova plugins. There
are a number of common sort of default plugins and then there are also custom
plugins that can interact with the device itself and in their case they're
interacting with the mobile operating system and a native code to be able to
work on all those pieces. Now there are several of these plugins included inside
of what we refer to as the default native shell. So there is the Camera
plugin that can take pictures and scan items. There's the Contacts that gets you
to the address book. Location which sort of gives you where you're located in a
given time, and Network Status so which networks are you connected to and what
is your current status on those networks
there's also the ability to access the calendar and receive local notifications
from the device and that would let our apps sort of create their own
notifications as needed. So what are the other plugins that are available and
we'll go through most of these so there is something to record audio there's a
scanner to help do bar codes there's something that can detect beacons and
and tell us our sort of smaller more refined location. MicroBlink and Card
IO do some scanning. Composing emails, transferring files, setting up a geofence
doing near field communication, and being able to be a little bit more secure by
using Touch ID. So the Audio Record plugin will capture audio and save it
to the file system and then the path can be returned by the plugin so that we
know where that is
you can adjust this to make sure we don't record forever so there is a
maximum recording time that can be set and then you can sort of preview and
decide whether to save it or you can just then throw it away
there is a barcode scanning plugin that allows us to scan barcodes and there are
a lot of different types of barcodes and including the QR Code. so depending on
what you're trying to scan the barcode scanning plugin if it's a standard
and popular symbology should be able to go ahead and handle that for you.
There's a beacons plugin. The beacons are wireless sensors and they broadcast tiny
radio signals that the device can receive and then react to. So the beacons
can be placed in different locations they can be a place two objects they use
bluetooth for low-energy and basically you're limited to a range of about 70
meters so it's not going to work too much further outside of that but the
beacon itself will be on when it's sitting up normally if you turn it
upside down it will shut itself off but this gives us a little bit more of a
fine-grained idea of where our location is and that can sometimes give us extra
contextual awareness. So this plugin will go ahead and handle local
notifications and other types of things because it will need to know how many
beacons and where you are so there can be different types of updates as that
that goes through. Blink ID knows how to scan and decode lots of different types
of documents now this requires a license that you need to go out and get from
microlink microblink but it then will scan certain types of barcodes, your
passport, identity cards. So it's a fairly useful plugin to have. Similar to that
there's Card.io that can go ahead and scan any type of credit card information
so it will attempt to read and find that information
and there's a pretty cool demo out there on how that part works. There's also the
email composer, if you need to compose an email in your app somewhere it's easier
to use the plugin the plugin will then leverage and connect to the native mail
composer on the device, and then you can send out emails as needed.
There's also the file transfer, uploading or downloading files depending on how
many files you have on your device and how big they are you may want to be able
to upload them to the device or download them off the device to make things a
little bit easier.
There's a geofence plugin that creates a virtual sensor perimeter around a
particular geographic area. So to do that you have to define a set of coordinates
as to where the virtual events should be.
you can either do a circular region where there's a point and a radius or
you can do different shapes like polygons. So that you know where the
fence is in exact relationship to the different things that you're looking for.
So your position can be monitored relative to the fence, whether you're
inside or outside of it, and then it can send notifications and alerts when you
walk across the boundary of the fence. So tense radius needs to be at least a
hundred meters so it has to be a decent-sized area as far as the
perimeter and fence are concerned.
There is a near-field communication plugin that enables near-field
communication. It's a subset of RFIDs specification and it's based on in
interesting inductive coupling capability that basically lets there be
certain types of active and passive devices and they can transfer energy and
communicate even if something doesn't sort of habit of battery in its own set
of energy, but we're talking about very short distances. Here you pretty much
have to be within 4 centimeters of each other or 2 inches to be able to do
this. Now the near-field communication also can read and write different types
of data
most of the time it's just reading but if you wanted to go ahead and write you
can do that there is a particular transfer rate and that means that you're
not going to be able to transfer huge amounts of information back and forth
this way, but you could go ahead and use it to do relatively simple stuff. A big
plugin that can be very useful for the Apple side of things is Touch ID, and
that gives you fingerprint recognition on the Apple devices so this can be used
for authorization to basically say okay you're trying to do something you know, I
need to just verify that this is really you, so go ahead and give us your
fingerprint again and then it will allow whatever is going to happen next to
occur so at this point there are a little bit of a limitation for touch ID you can't
just have any old iPhone you need an iPhone 5S or better, or some of the more recent
iPads to be able to work with those. So those are some of the plugins that are
out there there is also the thought of I would like to create my own plugin.
Well if you go out to the Apache Cordova site you can go to the area on plugins
and you'll actually find that there are over 1,500 plugins
out there. So if you go research some of the plugins and you happen to find one
you like and you wanted to create an OutSystems resource inside of a module
to be able to work with that plugin, first thing you want to do is create the
application and select the blank module inside of it. Then you could go ahead and
enter the configuration for this plugin and the module. So basically we need the
URL of where that information is and then we could create some client actions
to define the API, and we want to make sure that they're public so that we can reuse
these whenever we need them. So there are different types of apis inside of the
application that may want to use the plugin, so we have to understand okay
given the plugin what are we going to expose and how are people going to use
that API. So let's go through it step-by-step.
If we go out to Apache Cordova we look at the plugins that are there we could
go ahead and type something in and it would search for those types of plugins
for us so here we're looking for a flashlight you can immediately find one
and it gives you some information like is this available for android, is it
available for Apple, how many times has this been downloaded, when was the last
time the code was updated. So you begin to get a better idea of each plugin and
how up-to-date it is and and what are the capabilities that it can do so if we
went into our cordova plugin flashlight and looked at it in a little
bit more detail. We can see that the installation says okay go ahead and use
cordova plugin add the plugin flashlight, and it's available at this
URL. No,w down below, you can also see there is the usage and the usages here
is the JavaScript, and here's the JavaScript code
that's going to be called so there is
you know being able to take the flashlight and switch it on and then
switch it off or maybe just toggle it, but those types of information are there.
So for us to create this plugin as its own module, we go out and create the app,
create the module, and then underneath the module down in the advanced area just
right next to the web services we have this configuration.
And if we go in and we place in the configuration that this is going to be a
plugin, and the URL is going to GitHub and going to get this PhoneGap plugin
for the flashlight.
It will then go ahead and register and configure that so we know which of the
plugins is going to be used. Now once we know the plugin and it's configured and
registered, we then need to define the JavaScript behavior so here we can go in
and say alright, we're going to take the window and use the plugins for the
flashlight and switch it on.
now once we have this setup, we now have the JavaScript to be able to turn on
that particular part of our our flashlight so in this case here you can
see that this is the turn on method, and it's just going to do what it needs to
you could do the same thing for the turn off action. So being able to know
what the JavaScript is, and then tie it to the OutSystems action, so that we can
make that available inside the plugin, then we'll be in good shape and then
down here once everything is defined properly we want to make sure that it's
public, so that people can go ahead and use it.
Once we use the plugin then the plugin will activate the JavaScript and then the
JavaScript will actually be doing what needs to be done and the Cordova
framework will be interacting with the devices to go ahead and make that happen.
So in this section we talked a little bit about what the plugins are we also
went over some of the common plugins that are available and they're available
by default in the shell.
We looked at what's available from the Forge and how you could go ahead and
create your own. There's one other scenario here where you might want to
create a plugin that has never existed before and no one from Apache Cordova's
framework has attempted to do something like that
in that case you might need to go out and write the real code, and kind of go
through the Cordova approach to be able to build something like that, but once
Cordova has it as a registered plugin it's very easy for us to wrap that and
make it available inside of OutSystems. So a lot of different types of plugins,
lots of information about plugins, look into the reference documentation for
more details about how to use some of these plugins and how to create the new
ones.