3

我正在使用android中的DownloadManager类从服务器下载数据。数据保存到外部存储器。但我想将它们保存到内存中。我做了我的研究,我发现从这个link。我试过的cyngus第二个解决方案:Android:不能保存从服务器使用DownloadManager下载到内部存储器的数据

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); 

它没有工作,它给我的错误:java.lang.IllegalArgumentException: Not a file URI: content://com.provider.Downloads/downloads。我做错了什么?

回答

6

doc for DownloadManager.Request明确提到,你的任何的setDestination*方法设定的目标必须是在外部存储设备和您的应用程序必须有WRITE_EXTERNAL_STORAGE权限:

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.

我不明白怎么会是可能的在此提供内部存储路径。

+0

mmmm好的,但根据此链接:http://stackoverflow.com/questions/6494627/download-to-internal-memory-possible DownloadManager如何写入内容提供商? – 2012-07-12 09:31:20

+0

我不认为这也可以。 'DownloadManager.Request'适用于_file paths_而不适用于'ContentProvider'。如果您查看“DownloadManager”的源代码,您会发现最终将您在setDestination *中设置的路径视为文件路径。 – curioustechizen 2012-07-12 09:40:04

+0

mm好的,谢谢!所以我必须将数据保存到外部存储器或使用另一个类,而不是DownlaodManager。 – 2012-07-12 09:48:16

相关问题