cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Jan de Wit <ede...@redhat.com>
Subject Android Plugin API
Date Wed, 28 May 2014 12:50:11 GMT
Hi,

When one is writing a plugin for android ATM the api that you have to implement has a execute
method that has the action as a string:
@Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
throws JSONException {
        if ("beep".equals(action)) {
            this.beep(args.getLong(0));
            callbackContext.success();
            return true;
        }
        return false;  // Returning false results in a "MethodNotFound" error.
    }
When you have multiple actions this method gets very long, if you compare this with iOS here
you don’t need a method like this you could ‘just’ implement the method directly:
- (void)beep:(CDVInvokedUrlCommand*)command
    {
        CDVPluginResult* pluginResult = nil;
        NSString* myarg = [command.arguments objectAtIndex:0];

        if (myarg != nil) {
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
        } else {
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Arg
was null"];
        }
        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    }
We could do the same thing for android if we use reflection, making the API more similar and
removing all the string test by the user. What do you think?

Cheers,
	Erik Jan
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message