2013-05-25 215 views
7

我使用的下载管理器,当我使用Android的下载管理器setDestinationInExternalFilesDir

setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, "example.ext"); 

的文件被下载到Android /数据/ com.example.app /文件/ Download文件夹。

当我尝试

setDestinationInExternalPublicDir("/folder", "example.ext"); 

我得到: IllegalStateException: Cannot create directory mnt/sdcard/folder。 我也设置了WRITE_EXTERNAL_STORAGE权限。

我在做什么错?

回答

0

你为什么不使用absolute路径ExternalFileDir

File sdCard = Environment.getExternalStorageDirectory(); 
String folder = sdCard.getAbsolutePath() + "/YourFolder" ; 
File dir = new File(folder); 
if (!dir.exists()) { 
if (dir.mkdirs()) { 
    Log.i(Tag,"Directory Created"); 
    } 
} 

我想这甚至可能为你工作。

+0

我尝试以下。 downloadRequest.setDestinationInExternalFilesDir(v.getContext(),folder,down.getTitle()+“。epub”)); 但该文件被下载到 file:///mnt/sdcard/Android/data/com.example.app/files/*folder-path* –

+0

我暂时通过从Android/data/com.example.app/files到我需要的目录。 –

0

使用request.setDestinationInExternalPublicDir("/folder", "FileName.extention");

这个工作对我来说..