我尝试使用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
?
答案 0 :(得分:3)
请改用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);