问题描述
我已经使用Phonegap的File API将文件成功下载到我的Android手机。我想将文件下载到手机上的下载文件夹。例如,如果您从电子邮件中下载附件,附件将发送到您的下载文件夹。这是我的JS代码,它将文件下载到file:// mnt / sdcard /:
I have successfully downloaded a file to my Android phone using Phonegap's File API. I would like to download the file to the Downloads folder on my phone. For example, if you download an attachment from an email, the attachment goes to your Downloads folder. Here is my JS code, which downloads the file to "file://mnt/sdcard/":
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getFile('myfile.jpg', {
create: true,
exclusive: false
}, function(fileEntry) {
var localPath = fileEntry.fullPath,
fileTransfer = new FileTransfer();
fileTransfer.download(uri, localPath, function(entry) {
console.log("download complete: " + entry.fullPath);
}, function (error) {
console.log('download error: ' + error.code);
console.log("download error source " + error.source);
console.log("download error target " + error.target);
});
}, downloadError);
}, downloadError);
必须有一种方法来访问下载文件夹,因为我一直看到这个功能在其他应用程序中。
There has to be a way to access the Downloads folder, because I see this functionality all of the time in other apps.
推荐答案
您可以通过在getFile方法中指定文件将文件发送到下载文件夹...
You can send the file to the download folder by specifying it in the getFile method...
getfile('download/myfile.jpg' ...)
这不会触发下载文件下载时通知您的DownloadManager。我仍然试图找到一个通过phonegap访问DownloadManager类的解决方案。我在这里提出了这个问题
This doesn't trigger the DownloadManager which notifies you when a file has been downloaded. I am still trying to find a solution for having access to the DownloadManager class through phonegap. I have asked this question here How do you download a file to Android's Downloads folder using Phonegap?
这篇关于如何使用Phonegap将文件下载到Android的Downloads文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!