You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ONLY time we should be returning FALSE is when it's an invalid action, otherwise
Any other action returns false and results in an INVALID_ACTION error, which translates to an error callback invoked on the JavaScript side
So that's why I was getting all these Invalid Action errors and error not handled in promises ... due to incorrect Android codebase returning FALSE when it should always return TRUE ... even at that ... almost all functions should be void not boolean bc there's no reason to return true/false as true should always be returned to exec because the callback handles the error! GAWRR!
packageorg.apache.cordova.plugin;
importorg.apache.cordova.CordovaPlugin;
importorg.apache.cordova.CallbackContext;
importorg.json.JSONArray;
importorg.json.JSONException;
importorg.json.JSONObject;
/*** This class echoes a string called from JavaScript.*/publicclassEchoextendsCordovaPlugin {
@Overridepublicbooleanexecute(Stringaction, JSONArrayargs, CallbackContextcallbackContext) throwsJSONException {
if (action.equals("echo")) {
Stringmessage = args.getString(0);
this.echo(message, callbackContext);
returntrue;
}
returnfalse;
}
privatevoidecho(Stringmessage, CallbackContextcallbackContext) {
if (message != null && message.length() > 0) {
callbackContext.success(message);
} else {
callbackContext.error("Expected one non-empty string argument.");
}
}
}
The necessary imports at the top of the file extends the class from CordovaPlugin, whose execute() method it overrides to receive messages from exec(). The execute() method first tests the value of action, for which in this case there is only one valid echo value. Any other action returns false and results in an INVALID_ACTION error, which translates to an error callback invoked on the JavaScript side.
Next, the method retrieves the echo string using the args object's getString method, specifying the first parameter passed to the method. After the value is passed to a private echo method, it is parameter-checked to make sure it is not null or an empty string, in which case callbackContext.error() invokes JavaScript's error callback. If the various checks pass, the callbackContext.success() passes the original message string back to JavaScript's success callback as a parameter.
The ONLY time we should be returning FALSE is when it's an invalid action, otherwise
So that's why I was getting all these Invalid Action errors and error not handled in promises ... due to incorrect Android codebase returning FALSE when it should always return TRUE ... even at that ... almost all functions should be
void
not boolean bc there's no reason to return true/false as true should always be returned toexec
because the callback handles the error! GAWRR!The necessary imports at the top of the file extends the class from CordovaPlugin, whose execute() method it overrides to receive messages from exec(). The execute() method first tests the value of action, for which in this case there is only one valid echo value. Any other action returns false and results in an INVALID_ACTION error, which translates to an error callback invoked on the JavaScript side.
Next, the method retrieves the echo string using the args object's getString method, specifying the first parameter passed to the method. After the value is passed to a private echo method, it is parameter-checked to make sure it is not null or an empty string, in which case callbackContext.error() invokes JavaScript's error callback. If the various checks pass, the callbackContext.success() passes the original message string back to JavaScript's success callback as a parameter.
https://cordova.apache.org/docs/en/latest/guide/platforms/android/plugin.html
The text was updated successfully, but these errors were encountered: