Skip to content

Instantly share code, notes, and snippets.

@Maxim-Kolmogorov
Created April 14, 2021 08:40
Show Gist options
  • Save Maxim-Kolmogorov/56b0e5d799612c96b7c7b2c3acd91a79 to your computer and use it in GitHub Desktop.
Save Maxim-Kolmogorov/56b0e5d799612c96b7c7b2c3acd91a79 to your computer and use it in GitHub Desktop.
Cordova Java plugin: part 2
package com.plugin;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONException;
import android.content.Context;
import android.widget.Toast;
public class EchoTest extends CordovaPlugin {
@Override
public boolean execute(
String action,
JSONArray args,
CallbackContext callbackContext
) throws JSONException {
if ("echo".equals(action)) {
echo(args.getString(0), callbackContext);
return true;
}
return false;
}
private void echo(String msg, CallbackContext callbackContext) {
if (msg == null || msg.length() == 0) {
callbackContext.error("Empty message!");
} else {
Toast.makeText(webView.getContext(), msg, Toast.LENGTH_LONG).show();
callbackContext.success(msg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment