The overall architecture of these plugins is the following:
- a native component making the job, for example a Java Android file
This bridge is composed of:
- one native file (i.e. one Java file),
- and generally one quick configuration file specific to the platform.
Let’s take a simple example:
- In Java you have a method
String sayHello(String name)which return « Hello
But PhoneGap is providing us:
- In the Java side: a method
PluginResult execute(String methodName, JSONArray arguments, String callbackId)
PhoneGap.exec(successCallback, failureCallback, 'plugin name', 'method name', [parameters])
The goal of the bridge is to use these methods provided by PhoneGap to hide the complexity and provide simple methods to the user. We will show how to learn that later. Let’s continue with principles around this bridge.
execute(Java side) and
- In our bridge, we only have to transform:
- Java side: our Java parameters into a JSON string, our return value(s) into a JSON string (or a normal string if we only have one simple value)
Ok fine! Now, we are going to create examples of Android PhoneGap plugin! Hum… let’s say: in an other article, right?