Skip to content

Instantly share code, notes, and snippets.

@pbakondy
Created April 14, 2015 08:21
Show Gist options
  • Save pbakondy/e1910784c96460e31060 to your computer and use it in GitHub Desktop.
Save pbakondy/e1910784c96460e31060 to your computer and use it in GitHub Desktop.
How to return boolean value in a cordova android plugin
// How to return boolean value in a cordova android plugin
public class ExampleClass extends CordovaPlugin {
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("test")) {
try {
boolean result = testAction();
callbackContext.sendPluginResult(new PluginResult(Status.OK, result));
} catch (Exception e) {}
return true;
} else {
return false;
}
}
private static boolean testAction() {
return true;
}
}
@BahiHussein
Copy link

Thanks for the code. I'm getting the following error, can you help?
callbackContext.sendPluginResult(new PluginResult(Status.OK, result)); ^ symbol: variable Status

@pbakondy
Copy link
Author

You need the following:

import org.apache.cordova.PluginResult.Status;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment