cordova:从 url 下载到 android 下载文件夹

cordova: download from url to android download folder

在开始之前,我尝试了以下堆栈溢出的答案。

Download file to downloads folder ios/android using phonegap

Download a file to Downloads folder of device using Cordova FileTransfer

http://www.phonegaptutorial.com/downloading-an-image-from-the-internet-with-phonegap/

但一点运气都没有。

我正在尝试从 Internet 下载文件。 我的目标是下载 Android phone.

上的下载文件夹中的文件

我尝试了以上所有答案,而且我还使用了来自 cordova 站点的 cordova 示例。

https://cordova.apache.org/docs/en/2.0.0/cordova/file/filetransfer/filetransfer.html

function downloadCL(){

var url = "http://www.phonegaptutorial.com/wp-content/uploads/examples/phonegap-logo.png";

// we need to access LocalFileSystem
window.requestFileSystem(window.LocalFileSystem.PERSISTENT, 0, function(fs)
{
     // create the download directory is doesn't exist
    fs.root.getDirectory('downloads', { create: true });

    // we will save file in .. downloads/phonegap-logo.png
    var filePath = fs.root.fullPath + '/downloads/' + url.split('/').pop();
    var fileTransfer = new window.FileTransfer();
    var uri = encodeURI(decodeURIComponent(url));

    fileTransfer.download(uri, filePath, function(entry)
    {
        alert("Successfully downloaded file, full path is " + entry.fullPath);
    },
  function(error)
    {
        console.log("Some error " + error.code + " for " + url +);
    }, 
    false);
}
                          };
};

任何建议如何实现这一目标。

分叉,
你必须选择下载文件 url,
本地下载文件位于此处 -
文件:///storage/emulated/0/download 这个 link 可能对你有帮助 -

添加文件传输插件下载如-

https://github.com/cfjedimaster/Cordova-Examples/tree/master/asyncdownload

根据要求任意选择