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

时间:2021-09-21 21:17:51

I want to get the link of an image clicked inside a Webview to display it in an new intent. 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.

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

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

1 个解决方案

#1


1  

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

#1


1  

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