4

I am downloading data from server using the DownloadManager class in android. Data are saves to the external memory. But I want to save them to the internal memory. I did my researches and what I've found is from this link. I tried the second solution of cyngus :

public static final String PROVIDER_NAME = "com.provider.Downloads";
public static final Uri CONTENT_URI = Uri.parse("content://"+ PROVIDER_NAME + "/downloads")

DownloadManager.Request req = new DownloadManager.Request(Uri.parse(LINK));
req.setDestinationUri(CONTENT_URI);

It didnt work, it gave me the error: java.lang.IllegalArgumentException: Not a file URI: content://com.provider.Downloads/downloads. What I am doing wrong?

Community
  • 1
  • 1
b.i
  • 1,087
  • 4
  • 22
  • 43

1 Answers1

6

The doc for DownloadManager.Request clearly mentions that the destination you set for any of the setDestination* methods must be on external storage and that your app must have WRITE_EXTERNAL_STORAGE permission:

Set the local destination for the downloaded file. Must be a file URI to a path on external storage, and the calling application must have the WRITE_EXTERNAL_STORAGE permission.

I don't see how it would be possible to provide path to internal storage here.

Community
  • 1
  • 1
curioustechizen
  • 10,572
  • 10
  • 61
  • 110
  • mmmm ok, but according to this link: http://stackoverflow.com/questions/6494627/download-to-internal-memory-possible how can DownloadManager write to a content provider? – b.i Jul 12 '12 at 09:31
  • I don't think that will work either. The `DownloadManager.Request` works with _file paths_ and not with `ContentProvider`s. If you look at the source code for `DownloadManager` you'll see that ultimately the path that you set in setDestination* is treated as a file path. – curioustechizen Jul 12 '12 at 09:40
  • mm ok, Thank you! So I have to save data to the external memory or to use another class than DownlaodManager. – b.i Jul 12 '12 at 09:48