gpt4 book ai didi

android - DownloadListener 不下载图片?

转载 作者:行者123 更新时间:2023-11-30 03:41:02 24 4
gpt4 key购买 nike

在我的 Android 应用程序中,我使用带有 downloadListener 的 WebView。我想访问一个 Intranet 站点,当单击一个链接时,使用 mimetype 信息决定如何处理该文件。

问题在于引用图像文件(png、jpg 等)的链接。它们不会触发监听器,而是自动在新页面中显示文件,跳过监听器。

我怎样才能改变这种行为?

我的代码没什么特别的...

@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 是扩展WebViewClient 的类

public class MiWebClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
}

最佳答案

基于documentation :

Registers the interface to be used when content can not be handled by the rendering engine, and should be downloaded instead. This will replace the current handler.

由于图像可以由渲染引擎处理,它不会下载它,因此不会调用下载管理器。

关于android - DownloadListener 不下载图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15746077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com