我已使用 Phonegap 的 File API 成功将文件下载到我的 Android 手机。我想将文件下载到手机上的“下载”文件夹中。例如,如果您从电子邮件中下载附件,该附件将转到您的“下载”文件夹。这是我的 JS 代码,它将文件下载到“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);
必须有一种方法可以访问“下载”文件夹,因为我一直在其他应用程序中看到此功能。