1

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;
    }
}
Desenfoque
  • 804
  • 2
  • 11
  • 30

1 Answers1

1

Based on the 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.

Since, images can be handled by rendering engine, it doesn't download it and as result doesn't call download manager.

Victor Ronin
  • 22,758
  • 18
  • 92
  • 184