16

I am using downloadmanager.request enqueue setDestinationUri to download files.

Is it possible to download the files to the internal memory location of the device where it can be persistent?

I am using Android 3.1 Xoom device and it does not really have a functional SD card on it though the app allows us to write to /mnt/ sdcard location.

Any way of storing downloaded file onto internal memory?

TIA

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
VJ Vélan Solutions
  • 6,434
  • 5
  • 49
  • 63
  • Doesn't /sdcard on a honeycomb device write to internal memory anyway? Is this not what you want? – maxpower47 Jun 27 '11 at 14:45
  • 2
    I don't think /mnt/sdcard qualifies as internal memory. The absolute path for that location is given by Environment.getExternalStorageDirectory().getAbsolutePath() and it's quite clear that it's External – VJ Vélan Solutions Jun 27 '11 at 14:58
  • What I'm saying is the xoom (and other HC devices) map /sdcard to a point in the internal 16 or 32GB of memory as a workaround for apps that expect an sdcard to be present. To apps it looks like its on an sdcard, but internally, its actually written to the internal flash. – maxpower47 Jun 27 '11 at 15:04
  • @maxpower47. I see. What would happen when Motorola fixes the SD card issue? – VJ Vélan Solutions Jun 27 '11 at 16:03
  • The current arrangement with Xoom will not change, even if the SD card slot on the motherboard is enabled. If the SD card slot is enabled, that SD card will be mapped to a different path. I'll also note that phones like the Nexus S that have no SD card have /sdcard mapped to an internal partition. Having something writeable at /sdcard is a requirement of the Android CDD. – cyngus Jun 27 '11 at 16:08
  • FYI, on the Asus Transformer, which has a working microsd card slot, the sd card is mounted at /Removable/MicroSD while the internal memory is mounted at /sdcard – maxpower47 Jun 27 '11 at 17:59
  • @ user693959 I am facing a similar problem, did u find a solution? I am trying (2), but till now, it is not working. Thanks! – b.i Jul 12 '12 at 06:50

1 Answers1

20

It is unlikely that DownloadManager will be able to do this. My assumption is that DownloadManager does not run in your process, but in another process controlled by the system. Internal storage locations are permissions protected and any location that you would provide would be accessible only to your application.

It seems like you have two options.

(1) Supply a file path on "external" storage, when it completes, copy to internal storage, and then delete the file on external storage.

(2) Create a ContentProvider which DownloadManager can write to and give it a URI that corresponds to this ContentProvider. The ContentProvider that you implement can write the file to internal storage since it will run in the context of your application.

xarlymg89
  • 2,552
  • 2
  • 27
  • 41
cyngus
  • 1,763
  • 13
  • 14
  • @cygnus - this sounds promising. Let me try (2) and will update the thread. Thanks. – VJ Vélan Solutions Jun 27 '11 at 15:39
  • 2
    @cyngus: could you give an example of option 2? – RvdK Oct 31 '12 at 09:55
  • 3
    Second approach will not work, as DownloadManager.Request accepts only file:// scheme URI's. – pepyakin Dec 24 '13 at 11:33
  • It would't be possible to create a directory in internal storage with public read/write/list permission and pass a file:/// URI to DownloadManager pointing to a file inside this directory? – romulof Nov 10 '15 at 14:06
  • 1
    If you use `FileProvider` then `DownloadManager` will crash with exception `java.lang.IllegalArgumentException: Not a file URI: content://your_file_provider_authotrity/file_path` As DownloadManager uses `file://` scheme to access the file and FileProvider will give you URI wil scheme as `content://` – Kalpesh Patel May 04 '16 at 05:33
  • 6
    @cyngus If you could confirm and update your answer then It would be helpful to future readers. – Kalpesh Patel May 04 '16 at 05:36
  • 1
    @prostock No i was not able to get it work. I had to resort to first approach. – Kalpesh Patel Oct 10 '17 at 02:27
  • Option #2 is not possible. There is a ticket here: https://issuetracker.google.com/issues/37118684 If you think this is valuable you should comment/star. – lostintranslation Jun 05 '18 at 14:26