function downloadFile() { alert(androidFile); try { // onDeviceReady(); var ft = new FileTransfer(); var uri = encodeURI(androidFile); var fileURL = fullPath + androidFile.substr(androidFile.lastIndexOf('/') + 1); alert("准备下载"+fileURL); ft.download( uri, fileURL, function(entry) { OpenFile(entry.fullPath); console.log("download complete: " + entry.toURL()); }, function(error) { alert("download error source " + error.source); alert("download error target " + error.target); console.log("download error source " + error.source); console.log("download error target " + error.target); console.log("upload error code" + error.code); }, false, { headers: { "Authorization": "Basic dGVzdHVzZXJuYW1lOnRlc3RwYXNzd29yZA==" } } ); } catch (e) { alert(e.name + ":" + e.message); } }
前提是安装插件:
cordova create my-app
cd my-app
cd plugin
cordova plugin add org.apache.cordova.file-transfer
cordova plugin add org.apache.cordova.file
cordova build android
测试版本是cordova 4.1.2