Reputation: 1665
I am trying to build a hello world plugin for android using Cordova.The project runs without errors but i cant the result.My logcat returns the error Error adding plugin
.Here is my code
javacript
window.func = function(str,callback){
alert("Outside Call Working");
cordova.exec(callback, function(err){alert(err)},"HelloPlugin","echo", [str]);
}
function callPlugin(str){
alert("JS Working");
window.func(str,function(){
alert("Done!");
});
}
Android
public class HelloPlugin extends CordovaPlugin{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if(action.equals("echo")){
String message = args.getString(0);
callbackContext.success(message);
return true;
}
callbackContext.success(action);
return true;
}
}
config.xml
<feature name="HelloPlugin">
<param name="android-package" value="com.ionicframework.myapp554544" />
</feature>
NOTE:
The above codes stolen from (Creating a helloWorld plugin for Android using Cordova and Eclipse) this question
EDIT
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- plugin bridge js -->
<script src="js/plugin.js"></script>
</head>
<body >
<a onclick="callPlugin('Plugin Working!')">Click me</a>
</body>
</html>
plugin.js
window.func = function(str,callback){
alert("Outside Call Working");
cordova.exec(callback, function(err){alert(err)},"org.apache.cordova.plugin.HelloPlugin","echo", [str]);
}
function callPlugin(str){
alert("JS Working");
window.func(str,function(){
alert("Done!");
});
}
HelloPlugin.java
package com.ionicframework.myapp554544;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;
public class HelloPlugin extends CordovaPlugin{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if(action.equals("echo")){
String message = args.getString(0);
callbackContext.success(message);
return true;
}
callbackContext.success(action);
return true;
}
}
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.ionicframework.myapp554544" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<feature name="Keyboard">
<param name="android-package" value="com.ionic.keyboard.IonicKeyboard" />
<param name="onload" value="true" />
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<!-- Here is the plugin entry -->
<plugin name="HelloPlugin" value="com.example.plugintest.HelloPlugin" />
<!-- end of plugin entry -->
<name>myApp</name>
<description>
An Ionic Framework and Cordova project.
</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">
Ionic Framework Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="BackupWebStorage" value="none" />
</widget>
Upvotes: 0
Views: 725
Reputation: 15836
cordova.exec(callback, function(err){alert(err)},"HelloPlugin","echo", [str]);
should be changed to :
cordova.exec(callback, function(err){alert(err)},"org.apache.cordova.plugin.HelloPlugin","echo", [str]);
aslo change your xml entry to be:
<plugin name="HelloPlugin" value="com.example.plugintest.HelloPlugin" />
Upvotes: 1