0

My HTTP-server allows downloading files with a 'dynamic' url: e.g. http://myserver.com/query?id=12345 which will give me my_song.mp3. The filename is indicated in the content-disposition header. Downloading this kind of file with Android DownloadManager works fine but I want to be able to control where the file is being saved to. The normal way to do this would be to call

DownloadManager.Request r = new DownloadManager.Request(uri);

r.setDestinationInExternalPublicDir(String dirType, String subPath);

Unfortunately this requires to know the filename up front which I don't know. I tried calling the above function with a null for subPath but it does not work...

Paul Praet
  • 1,367
  • 14
  • 25
  • 1
    try to use `HttpClient` or `UrlHttpConnection` with `HEAD` request ... it should return all headers without body ... then analyze `Content-Type` header (for file name) .... or just use http://developer.android.com/reference/java/util/UUID.html to generate some "random" name ... – Selvin Apr 05 '13 at 12:05
  • @Selvin: that is definitely an good idea but I was hoping for something less hacky :) – Paul Praet Apr 05 '13 at 13:20

0 Answers0