如何使用Phonegap将文件下载到Android的下载文件夹? [英] How do you download a file to Android's Downloads folder using Phonegap?

查看:123
本文介绍了如何使用Phonegap将文件下载到Android的下载文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功使用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类。我在此处提出了此问题如何下载文件到android的下载使用phonegap?

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" using phonegap?

这篇关于如何使用Phonegap将文件下载到Android的下载文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆