Actually, this is not very difficult. Here I will show you how to call native code from javascript inside the page and vice versa:
Calling native code from a web view :
When creating a web view, add a javascript interface (basically a java class whose methods will be displayed through javascript in the web view.
JavaScriptInterface jsInterface = new JavaScriptInterface(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(jsInterface, "JSInterface");
javascript ( , )
public class JavaScriptInterface {
private Activity activity;
public JavaScriptInterface(Activity activiy) {
this.activity = activiy;
}
public void startVideo(String videoAddress){
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(videoAddress), "video/3gpp");
activity.startActivity(intent);
}
}
, HTML , :
<script>
function playVideo(video){
window.JSInterface.startVideo(video);
}
</script>
, ?
javascript :
, HTML, WebView, javascript:
<script>
function function(){
}
</script>
WebView :
webView.loadUrl("javascript:function()");