How do you download a file to Android's Downloads folder using Phonegap?

前端 未结 4 1382
天涯浪人
天涯浪人 2021-01-05 07:10

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

4条回答
  •  生来不讨喜
    2021-01-05 07:27

    I had the same problem, but I solved it like this:

    //if IOS cordova.file.documentsDirectory
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (fileEntry) {
      var filepath = fileEntry.toURL() + filename;
      var fileTransfer = new FileTransfer();
      console.log('FilePath ' + filepath);
      fileTransfer.download(uri, filepath,
        function (fileEntry) {
          console.log("download complete: " + fileEntry.toURL());
        },
        function (error) {
          console.log("ErrorDownload: " + JSON.stringify(error));
        },
        true,
        {}
      );
    });
    

提交回复
热议问题