[英]Get link of the clicked image in a webview
I want to get the link of an image clicked inside a Webview to display it in an new intent.我想获取在 Web 视图中单击的图像的链接,以在新的意图中显示它。 The site that i want the image from is not opening the images in fullscreen when clicked.单击时,我想要图像的站点没有以全屏模式打开图像。 I want something like the code down bellow but the website doesn't open images in the same tab.我想要类似下面的代码,但该网站不会在同一选项卡中打开图像。
Reference Code:参考代码:
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url == null){
return false;
}else if (url.trim().toLowerCase().endsWith(".img")) {//use whatever image formats you are looking for here.
String imageUrl = url;//here is your image url, do what you want with it
}else{
view.loadUrl(url);
}
}
}
public class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url == null){
return false;
}else if (url.trim().toLowerCase().endsWith(".img")) {//use whatever
image formats you are looking for here.
String imageUrl = url;//here is your image url, do what you want with
it
Intent intent = new Intent(this, NewActivity.class);
//pass from here the data to next activity and load there
intent.putExtra("yourURL", imageUrl);
startActivity(intent)
}else{
view.loadUrl(url);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.