Created
April 14, 2021 08:40
-
-
Save Maxim-Kolmogorov/56b0e5d799612c96b7c7b2c3acd91a79 to your computer and use it in GitHub Desktop.
Cordova Java plugin: part 2
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
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