File download to Android download folder in Cordova

五迷三道 提交于 2019-12-02 03:36:22

问题


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.

来源:https://stackoverflow.com/questions/41152137/file-download-to-android-download-folder-in-cordova

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!