I generated the code using the Cordova 4.0.0 CLI.
Now I try to write a Plugin for Android (MyPlugin) to execute native code from the webview. But everytime i try to call the plugin's method I receive the errormessage:
exec() call to unknown plugin
I tried different mappings in the config.xml (and also created a plugin.xml). But nothing works for me. Also the API is not very helpful.
Has anybody an idea how to realize this or what is wrong with my implementation?
Here is my code:
com.cordovaDemo.MyPlugin.java
public class MyPlugin extends CordovaPlugin {
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
//MyCode
callbackContext.success(action);
return true;
}
index.html
<head>
...
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<title>Hello World</title>
<script>
window.func = function(str,callback){
cordova.exec(callback, function(err){alert(err)},"MyPlugin","echo", [str]);
}
function callPlugin(str){
window.func(str,function(){
alert("Done!");
});
}
</script>
</head>
<body>
<div class="app">
<div id="deviceready" class="blink">
<a onclick="callPlugin('Test')">Click me</a>
</div>
</div>
</body>
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.touristmobile.cordovaDemo" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>CordovaDemo</name>
...
<content src="index.html" />
<access origin="*" />
<platform name="android">
<config-file target="config.xml" parent="/*">
<feature name="MyPlugin">
<param name="android-package" value="com.cordovaDemo.MyPlugin"/>
</feature>
</config-file>
</platform>
Edit:
Ok I think that now I understand the main idea of cordova plugins. A cordova plugin is independent from the "generated" Android Wrapper app.
In my case a cordova Webview should be an extension of my existing Android App, and the Webview should call functions and displayed information from the main app. In short: Is it possible to call functions located in classes on the same level as my CordovaActivity
Ok! I solved it using Cordova 3.6.4
An embedded Webview is possible: I followed this Guide: http://cordova.apache.org/docs/en/4.0.0/guide_platforms_android_webview.md.html#Android%20WebViews