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.