Android的下载管理器保存到文件夹中下载 [英] Android DownloadManager save to Download folder
问题描述
,我希望把下载标准下载文件夹中,以便人们可以使用文件管理器在寻找最明显的地方很容易地找到他们:
乌里downloadLocation = Uri.fromFile(新文件(Environment.DIRECTORY_DOWNLOADS,文件名));
request.setDestinationUri(downloadLocation);
龙基准= downloadManager.enqueue(请求);
但我得到一个异常,因为这不是一个外部驱动器。
请问有没有办法将文件下载到用户的下载文件夹?
此外,如果它们不具有什么外部存储器,只是内部
感谢。
乌里downloadLocation = Uri.fromFile(新文件(Environment.DIRECTORY_DOWNLOADS,文件名));
这是不是你如何使用 Environment.DIRECTORY_DOWNLOADS
。这不变的是为使用 getExternalStoragePublicDirectory()
:
文件DIR = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);dir.mkdirs();乌里downloadLocation = Uri.fromFile(新文件(目录,文件名);;
请注意该目录可能还不存在,所以你应该叫 mkdirs()
自己。
此外,如果它们不具有什么外部存储器,只是内部
块引用>几乎所有的Android设备具有外部存储器。外部!=移动。什么是Android SDK中所说的外部存储,也就是用户可以通过USB数据线接入,并且通常是在同一个分区为内部存储,在主板上的闪存。
I'm using DownloadManager to download file, I wanted to put the downloads in the standard download folder so people could easily find them using file manager looking in the most obvious place:
Uri downloadLocation = Uri.fromFile(new File(Environment.DIRECTORY_DOWNLOADS, filename)); request.setDestinationUri(downloadLocation); Long reference = downloadManager.enqueue(request);
But I get an exception because that isn't an external drive.
Is there no way to download a file to the user's download folder?
Also, what if they don't have external memory, just internal?
Thanks.
解决方案Uri downloadLocation=Uri.fromFile(new File(Environment.DIRECTORY_DOWNLOADS, filename));
That is not how you use
Environment.DIRECTORY_DOWNLOADS
. That constant is for use withgetExternalStoragePublicDirectory()
:File dir=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); dir.mkdirs(); Uri downloadLocation=Uri.fromFile(new File(dir, filename);;
Note that the directory may not exist yet, so you should call
mkdirs()
yourself.Also, what if they don't have external memory, just internal?
Practically all Android devices have external memory. External != removable. What the Android SDK refers to as "external storage" is what the user can access via the USB cable, and usually is on the same partition as "internal storage", in on-board flash memory.
这篇关于Android的下载管理器保存到文件夹中下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!