问题描述
在我的Android应用程序,我使用了downloadListener一个web视图。我想访问一个内部网站,当点击一个链接,决定如何使用MIMETYPE信息与文件做的。
问题是与参考图像文件(PNG,JPG等)的链接。相反,触发听者,他们表现出automaticaly在一个新的页面文件,跳过听众。
我怎样才能改变这种行为?
我的code是没什么特别的......
@覆盖
保护无效的onCreate(包savedInstanceState)
{
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
的WebView =(web视图)findViewById(R.id.webview);
webview.setWebViewClient(新MiWebClient());
webview.setDownloadListener(oyenteDescarga);
//...other的onCreate东西...相关没什么
}
DownloadListener oyenteDescarga =新DownloadListener()
{
@覆盖
公共无效onDownloadStart(URL字符串,字符串的userAgent,字符串contentDisposition,字符串MIMETYPE,长CONTENTLENGTH)
{
//...I想在这里使用的mimetype,但是当我点击一个图像,一个例子监听器就不会被触发:
Toast.makeText(getBaseContext(),网址:+网址,Toast.LENGTH_SHORT).show(); //它不显示当我点击一个链接引用的图像
}
};
MiWebClient是扩展WebViewClient类
公共类MiWebClient扩展WebViewClient
{
@覆盖
公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)
{
view.loadUrl(URL);
返回true;
}
}
根据文档:
一直以来,图像可以通过渲染引擎来处理,它不会下载它,并为因此不调用下载管理器。
In my Android app, I'm using a WebView with a downloadListener. I want access a intranet site and when click in a link, decide what to do with the file using mimetype info.
The problem is with the links referencing image files (png, jpg, etc.). Instead of triggering the listener, they show automaticaly the file in a new page, skipping the listener.
How can I change this behaviour?
My code is nothing special...
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webview = (WebView)findViewById(R.id.webview);
webview.setWebViewClient(new MiWebClient());
webview.setDownloadListener(oyenteDescarga);
//...other onCreate stuff... nothing relevant
}
DownloadListener oyenteDescarga = new DownloadListener()
{
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength)
{
//...I want to use mimetype here, but this listener is not triggered when I click an image, an example:
Toast.makeText(getBaseContext(), "URL:" + url, Toast.LENGTH_SHORT).show(); //it doesn't show when i click a link referencing an image
}
};
MiWebClient is a class that extends WebViewClient
public class MiWebClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
}
Based on the documentation:
Since, images can be handled by rendering engine, it doesn't download it and as result doesn't call download manager.
这篇关于DownloadListener不下载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!