Reputation: 6955
I am trying to create a Cordova Plugin using IBM Worklight. I followed the instructions mentioned in the IBM Worklight Getting Started page, but while checking trying it on a device I get the following:
02-13 17:58:15.182: D/PluginManager(21057): exec() call to unknown plugin: SamPlugin
I added the plugin in Config.xml as follows:
<plugin name="SamPlugin" value="com.samapp.plugins.samplugin.SamPlugin"/>
and then, i called the plugin from my JavaScript file as follows:
cordova.exec(success,failure,"SamPlugin","printMsg",[name]);
There are no errors while building the application.
Do I need to mention the plugin anywhere else?
Upvotes: 0
Views: 1125
Reputation: 44526
Looks to me like the way you have declared the plug-in in config.xml is incorrect...
This:
<plugin name="SamPlugin" value="com.samapp.plugins.samplugin.SamPlugin"/>
Should be:
<feature name="SamPlugin">
<param name="android-package" value="com.testapp.SamPlugin" />
</feature>
The above is the way Cordova plug-ins are declared in Cordova 3.x; Worklight 6.1 uses Cordova 3.1.
The above assumes you are using Worklight 6.1, because you mentioned that you've followed a Getting Started training module, which is now based on Worklight 6.1... If you are using a different Worklight version, you must mention the version number.
For example - an application that implements a Cordova plug-in that shares a link to a question via the native email app installed on the device (this doesn't really matter, it's just a "scenario"):
HTML:
<button onclick="openExternalApp()">Share Question</button>
JavaScript:
function openExternalApp() {
var QUESTION_LINK = $(".question_link").attr("href");
cordova.exec(onSuccess, onFailure, "OpenExternalAppPlugin", "openApp", [QUESTION_LINK]);
}
function onSuccess() {
WL.Logger.debug("*** Plug-in executed successfully.");
}
function onFailure() {
WL.Logger.debug("*** Plug-in failed to execute.");
}
android\native\res\xml\config.xml:
<feature name="OpenExternalAppPlugin">
<param name="android-package" value="com.testapp.OpenExternalAppPlugin" />
</feature>
android\native\src\com\YOUR_APP\OpenExternalAppPlugin.java:
The Java file containing the Java code of the Cordova plug-in...
Upvotes: 1