Changing the default action before loading a url link.
Last active
December 16, 2016 07:28
-
-
Save pokk/0a1a9631c1978561a6d4120366f0223b to your computer and use it in GitHub Desktop.
change URL request or set an action in WebViewClient
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
public class MyWebViewClient extends WebViewClient | |
{ | |
@Override | |
public boolean shouldOverrideUrlLoading(WebView view, String url) | |
{ | |
// Get the url final filename extension of url file. | |
String filenameArray[] = URLUtil.guessFileName(url, null, null).split("\\."); | |
String extension = filenameArray[filenameArray.length - 1]; | |
if (extension.equals("jpg")) | |
{ | |
// ♦♦ Open a image view to fit your device screen size. | |
String html = "<html>" + | |
"<head>" + "<title>" + "Image" + "</title>" +"</head>" + | |
"<body>" + "<center>" + | |
"<img src=\"" + url + "\" style=\"display: inline;height: auto;max-width: 100%;\" />" + | |
"</center>" + "</body>" + | |
"</html>"; | |
view.loadData(html, "text/html", null); | |
// This is important part. Before 'return true', you could do any action what you need. | |
return true; | |
} | |
return super.shouldOverrideUrlLoading(view, url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment