4

I have an Android app with a WebView inside. I need to be able to download files with original name (send by the server) from within WebView.

The problem is that the download link is like:

http://address/path/controller.php?action=userOpenFileExe&documentId=1036826

So the name of the file and its type is unknown until the download begins.

[EDIT:] Also the URL is accessible only after a login took place (thus is inside a HTTP session)

All the examples I saw until right now uses DownloadManager like:

DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);

but I do not know the fileName beforehand (it can be contract.pdf, picture.jpg, etc) as it is simply set by server size with:

Content-Disposition: attachment; filename=picture23.jpg

Note: Trying to find the file name by using :

URLUtil.guessFileName(...)

does trigger an additional request for the server, so I will get same download link requested twice (one for guessing the name and one for the actual download)

Alex
  • 5,510
  • 8
  • 35
  • 54

0 Answers0