Skip to content

Instantly share code, notes, and snippets.

@Ansh1234
Last active April 26, 2017 17:10
Show Gist options
  • Save Ansh1234/13a514c9c24efd1365001667c689f2f7 to your computer and use it in GitHub Desktop.
Save Ansh1234/13a514c9c24efd1365001667c689f2f7 to your computer and use it in GitHub Desktop.
public class WebViewJsInterface {
private WebView webView;
private Context context;
public WebViewJsInterface(Context context, WebView webView) {
this.webView = webView;
this.context=context;
}
@JavascriptInterface
public void handleMessage(String message) {
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}
@JavascriptInterface
public void setWebViewTextCallback(){
String script = WebViewUtils.formatScript("setText","This is a text from Android which is set " +
"in the html page.");
WebViewUtils.callJavaScriptFunction(webView,script);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment