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

1 に答える 1

1

ドキュメントに基づく:

レンダリング エンジンでコンテンツを処理できず、代わりにダウンロードする必要がある場合に使用するインターフェイスを登録します。これにより、現在のハンドラが置き換えられます。

画像はレンダリング エンジンで処理できるため、ダウンロードせず、結果としてダウンロード マネージャーを呼び出しません。

于 2013-04-01T17:44:41.650 に答える