Created
April 14, 2015 08:21
-
-
Save pbakondy/e1910784c96460e31060 to your computer and use it in GitHub Desktop.
How to return boolean value in a cordova android plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} |
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
Thanks for the code. I'm getting the following error, can you help?
callbackContext.sendPluginResult(new PluginResult(Status.OK, result)); ^ symbol: variable Status