Download de arquivo para a pasta de download do Android em Cordova
Aqui está o código.
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');
}
}
Se eu usarstore = cordova.file.externalDataDirectory;
o arquivo é baixado dentro do diretório do aplicativo.
Também tentei codificar o caminho, mas ele não está funcionando. Estou recebendo um alerta de sucesso, mas nenhum arquivo foi baixado. Estou testando no emulador.
Meu objetivo é baixar o arquivo na pasta de download.