正确使用URI.fromFile来设置下载文件的目的地

时间:2013-11-15 10:55:03

标签: android uri storage android-download-manager

我仍然不明白我的应用程序有什么问题。我是usind DownloadManager从服务器获取一些mp3文件,我想把它放在/ Podcasts默认的android文件夹,但我不能这样做。 我尝试了不同的方式,但没有成功。如果我使用

Uri destination = Uri.fromFile(new File(Environment.DIRECTORY_PODCASTS));

抛出异常:

java.lang.securityexception destination must be on external storage: file///Podcasts

为什么?

1 个答案:

答案 0 :(得分:0)

你可能会发现this thread useful。基本上,似乎只有系统应用才能访问媒体目录。你为什么不只使用exgternal目录?

String pathLocalFile = getExternalFilesDir( null ).getPath() 

将在外部存储器上返回您的应用程序目录,您可以在那里创建相关目录。