javascript - Phonegap: JS call to Java Method works only in 1 case -


i working on phonegap project @ stage of extending base capabilities of phonegap custom plugin. stupid problem having getting plugin react correctly. plugin if called 'echo' parameter should answer giving matched parameter name, same goes 'echo2'.

the strange part:

'echo' returns expected answer (it executes success callback) whereas 'echo2' variant returns error callback. running out of ideas...

the js definitions: identical functions (only 4th parameter different)

window.echo = function(str, callback) {             cordova.exec(callback, function(err) {                     callback('nothing echo.');                     }, 'echo', 'echo', [str]);        };  window.sync = function(str, callback) {             cordova.exec(callback, function(err) {                     callback('nothing echo.');                     }, 'echo', 'echo2', [str]);        }; 

the js calls on these functions:

echo('echo string', function(echovalue) {       alert(echovalue); });  sync('sync string', function(echovalue) {       alert(echovalue); }); 

java class:

public class echo extends cordovaplugin {     @override     public boolean execute(string action, jsonarray args, callbackcontext callbackcontext) throws jsonexception {         switch(action) {              case "echo":    string message = args.getstring(0);                             this.echo("call on: echo.echo()" + message, callbackcontext);                             return true;              case "echo2":   string message = args.getstring(0);                             this.echo("call on: echo.echo2()" + message, callbackcontext);                             return true;         }         return false;     }      private void echo(string message, callbackcontext callbackcontext) {         if (message != null && message.length() > 0) {              callbackcontext.success(message);         } else {             callbackcontext.error("expected 1 non-empty string argument.");         }     } } 

to having similar problem, here information on why did not work:

firstly: code works fine - problem doesn't lie here.

where's fault?

when asked question, java class named echo worked when class method being called. trying call other method fails because

phonegap build service not allow direct includes of plugins

but in case still partially worked because java class echo happens standard plugin phonegap build included me.

this echo plugin being included phonegap build happens have method echo resulted in success callback, obviously.

after further reading:

a tool called plugman (also developed adobe) handles custom plugin implementation adding created plugin phonegap project ... still testing , learning this, official information (and information found) available here:

leads deprecated pluginstall tool

plugman tool repo - github


Comments