0

In my app, I want download a zip file and unzip it.

In DownloadManager request I use this:

request.setDestinationInExternalPublicDir("/SingingStudio", "file.zip");

This is write file in external storage.

And when I want to access file:

String szip = Environment.getExternalStorageDirectory()+File.separator+"SingingStudio"+File.separator+"file.zip";

This is get file from internal storage. And getExternalStoragePublicDirectory("/") too.

So I can not find the file .

frogatto
  • 28,539
  • 11
  • 83
  • 129
user2563494
  • 189
  • 2
  • 9

1 Answers1

1

Quoting the documentation for setDestinationInExternalPublicDir(), the first parameter is "the directory type to pass to getExternalStoragePublicDirectory(String)". That method, in turn, has a limited set of values it accepts, and "/SingingStudio" is not one of them.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • but setDestinationInExternalPublicDir("/SingingStudio"...) is download file to external storage and i can see that – user2563494 Nov 26 '15 at 18:26
  • @user2563494: There is no guarantee that this will work on every device, and even if it does, there is no documented behavior for where `setDestinationInExternalPublicDir()` will download the file when you do not follow the documented options. Use `setDestinationInExternalPublicDir()` properly, then [use `getExternalStoragePublicDirectory()`](http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)) to get the location where the file was downloaded. – CommonsWare Nov 26 '15 at 18:30
  • i use getExternalStoragePublicDirectory("/SingingStudio") but this is return internal storege too – user2563494 Nov 26 '15 at 18:33
  • so how can i download file to my dir by downloadManager if my code is wrong – user2563494 Nov 26 '15 at 18:46
  • @user2563494: Start by reading [the documentation for `getExternalStoragePublicDirectory()`](http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)). Then, use one of the documented valid values for the parameter to that method, such as `Environment.DIRECTORY_DOWNLOADS`. Then, use that same value in your `setDestinationInExternalPublicDir()` call. – CommonsWare Nov 26 '15 at 18:57
  • tanks CommonsWare . but i want to download file to my folder – user2563494 Nov 26 '15 at 19:08
  • @user2563494: Then [use `setDestinationUri()`](http://developer.android.com/reference/android/app/DownloadManager.Request.html#setDestinationUri%28android.net.Uri%29), where you use `Uri.fromFile()` to point to the `File` on external storage where you want the data to be downloaded. Or, write your own download code, avoiding `DownloadManager`. – CommonsWare Nov 26 '15 at 19:11