在我的Android应用中,我正在使用带有downloadListener的WebView。我想访问一个内部网站点,当点击链接时,使用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;
}
}
答案 0 :(得分:1)