获取网页浏览中点击图片的链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取网页浏览中点击图片的链接相关的知识,希望对你有一定的参考价值。

我想获取在Webview中单击的图像的链接,以便在新的意图中显示它。我想要图像的网站在点击时不会全屏打开图像。我想要类似下面的代码,但网站不会在同一个选项卡中打开图像。

参考代码:

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);
 }
}
}

以上是关于获取网页浏览中点击图片的链接的主要内容,如果未能解决你的问题,请参考以下文章