Forked from wesleyduff/Pass data FROM android app TO webView HTML JavaScript function
Created
October 31, 2020 05:07
-
-
Save Ikhiloya/185bcd5e1642a4d345c7e9bc3fdea08c to your computer and use it in GitHub Desktop.
This file contains 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
//Java | |
webview.getSettings().setJavaScriptEnabled(true); | |
webview.loadUrl("<your html file>"); //not in scope of this gist | |
webview.setWebViewClient(new WebViewClient(){ | |
public void onPageFinished(WebView view, String url){ | |
//Here you want to use .loadUrl again | |
//on the webview object and pass in | |
//"javascript:<your javaScript function" | |
webview.loadUrl("javascript:myJavaScriptFunc('" + argumentPassingIn + "')"); //if passing in an object. Mapping may need to take place | |
} | |
}); | |
//HTML | |
<!DOCTYPE html> | |
<html> | |
<head><title>Demo</title></head> | |
<body> | |
<h1>Body</h1> | |
<script> | |
myJavaScriptFunc(val){ | |
//Do something with val | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment