Android下载管理器setDestinationInExternalFilesDir

Ara*_*san 13 android android-download-manager

我正在使用下载管理器,当我使用时

 setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, "example.ext");
Run Code Online (Sandbox Code Playgroud)

文件下载到Android/data/com.example.app/files/Download文件夹.

当我尝试

setDestinationInExternalPublicDir("/folder", "example.ext");
Run Code Online (Sandbox Code Playgroud)

我明白了: IllegalStateException: Cannot create directory mnt/sdcard/folder.我也设置了WRITE_EXTERNAL_STORAGE权限.

我究竟做错了什么?

MDM*_*lik 1

为什么不使用absoluteExternalFileDir的路径

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");
    }
}
Run Code Online (Sandbox Code Playgroud)

我想这可能对你有用。