2

I'm just working on the Android DownloadManager and I would like to save the file with the original file name, provided by the server. My current code:

    req.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI
                               | DownloadManager.Request.NETWORK_MOBILE)
   .setAllowedOverRoaming(false)
   .setTitle("Downloading..")
   .setDescription("Downloading ROM")
   .setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
                                      "NameOfFileOnCard");

Now, the file name in the download folder is configured, I marked it as NameOfFileOnCard. What do I have to change?

Please help!

yanniks
  • 299
  • 1
  • 6
  • 17

1 Answers1

0

Before I use code like this, you may try this:

 nameOfFile = URLUtil.guessFileName(fileURL, null, MimeTypeMap.getFileExtensionFromUrl(fileURL));

do not forget import:

 import android.webkit.MimeTypeMap;
 import android.webkit.URLUtil;
Fthr
  • 769
  • 9
  • 10