If I listen with DownloadListener
, I get the URL which I need to request after the browser already requested it. The browser already opened a connection to the URL (which is how it knows this is a download), why can't it pass me the connection?
I also tried to assign a custom WebViewClient
to the WebView
and use shouldOverrideUrlLoading
to catch URLs before they are requested. To download files that way, I request every URL before the browser and by it's Content-Type I decide whether to download it or not, if it is then I download it from the already-opened connection, otherwise I close the connection and instruct the browser to load it, and the browser... requests it again. Plus, in shouldOverrideUrlLoading
I'm not told which method and what cookies should I use to request the given URL.
How can I not unnecessarily request twice and still be able to download files with WebView?