我尝试使用 Android 下载管理器来下载文件。
request.setDestinationInExternalPublicDir("/myfile", "abc.txt");
enqueue = dm.enqueue(request);
因此文件将下载到 /storage/sdcard/myfile/abc.txt
。
但是,对于外部移除 SD 卡,路径为 /storage/sdcard1/
。
request.setDestinationInExternalPublicDir
默认为/storage/sdcard/
。
如何将下载路径设置为/storage/sdcard1/myfile/abc.txt
?
最佳答案
改用setDestination
。这是一个例子。将此 Environment.getExternalStorageDirectory()
更改为您的硬编码路径。
File root = new File(Environment.getExternalStorageDirectory() + File.separator);
Uri path = Uri.withAppendedPath(Uri.fromFile(root), "this_is_downloaded_file.png");
request.setDestinationUri(path);
关于Android 下载管理器下载到外部可移动 SD 卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24125040/