File download to Android download folder in Cordov

2020-04-15 05:14发布

问题:

Here is the code.

function downloadCL(){   
 document.addEventListener("deviceready", init, false);
    //The directory to store data
var store;

    var assetURL= encodeURI(website address to download the file);
    var fileName = assetURL.substr(assetURL.lastIndexOf('/') + 1); //Get filename of URL    
//    init();
    function init() {


alert("Checking for data file.");

  //  store = cordova.file.externalDataDirectory;
    store = "cdvfile://localhost/persistent/Download/";
    //Check for the file. 
    window.resolveLocalFileSystemURL(store + fileName, appStart, downloadAsset);
 }

    function downloadAsset() {
    var fileTransfer = new FileTransfer();
         alert(store);

        fileTransfer.download(assetURL, store + fileName, 
        function(entry) {
            alert("Success!");
            appStart();
        }, 
        function(err) {
            alert("Error");
            alert(err);
        });
}

 function appStart() {
    alert('done');
}   


}

If I use store = cordova.file.externalDataDirectory; then file get downloaded inside app directory.

I also tried hardcoding the path but it is not working. I am getting success alert but no files downloaded. I am testing it on emulator.

My target is to download the file in download folder.