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