Issue
if webview html content has few <img>
tags, is it possible to opens that image in fullscreen mode in new activity when user hit image in webview?
Solution
Yes it is. basically it is possible to invoke any kind of native Android code from within a WebView
. You define the methods you want to expose for calling from within the WebView
in a class, pass an instance of this class to the WebView
and from then on the methods are invocable just like javascript methods. here comes the example (this is copy-pasted form another answer of mine; you will need to replace the video intent with image displaying intent):
Calling native code from within web view:
When creating the web view add javascript interface (basically java class whose methods will be exposed to be called via javascript in the web view).
JavaScriptInterface jsInterface = new JavaScriptInterface(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(jsInterface, "JSInterface");
The definition of the javascript interface class itself (this is examplary class I took from another answer of mine and opens video in native intent)
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"); // The Mime type can actually be determined from the file
activity.startActivity(intent);
}
}
Now if yo want to call this code form the html of the page you provide the following method:
<script>
function playVideo(video){
window.JSInterface.startVideo(video);
}
</script>
So you need to add the appropriate method to JSInterface
and call the code from within the Web App.
Answered By - Boris Strandjev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.