1

I´ve an app, in which user can download files. For the download-process i use androids DownloadManager class. The file-download works perfectly, but i want to achieve, to store the file using the orginal file name of the downloaded file from the internet url. I´ve searched in the web and found different methods. The most just try to parse to file name from the url like so:

URL: https:// mysite.com/ filename.txt

parse the file name with url.substring(url.lastIndexOf('/') + 1) an you will have your file name...

But i need a method, that gets the file name also, if the file name is not included clearly in the url.

I also found some method to get the file name with

URLUtil.guessFileName(url, contentDisposition, mimetype)

I´ve implemented this method, but i´am getting always "download.bin" as my file name , which is incorrect. Maybe i have incorrect contentDisposition or mimetype for this method. How do you create contentDisposition or mimetype from just an url?

So i´m a bit helpless with this. Is there a safe working method with this.

  • I think you should look into this https://stackoverflow.com/questions/13321984/android-downloadmanager-get-filename – sanmeet Aug 16 '19 at 20:17
  • Ok, thank you very much! Is there another way to get the filename before the download completed. I want to set the destination file with correct file name... So i need the original file name, before i initialize my request object. In other words; before the download completed. Can we get the file name also before onComplete receive? – hauser resauh Aug 18 '19 at 10:42
  • see https://stackoverflow.com/a/63209848/191246 – ccpizza Aug 01 '20 at 20:40

0 Answers0