I'm creating my first webapplication using cordova 3.1.
In this app I need to be able to download a file to the phone and then open it, but i cant seem to get pass how to download the file.
I'm using the file-transfer code from cordovas doc page. Everyting is installed with CLI.
This is how far I've come:
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
download();
}
function download(){
var filePath = '/mnt/sdcard';
var fileTransfer = new FileTransfer();
var uri = encodeURI("https://www.dropbox.com/s/27bxw65u4ga5is0/test.pdf");
fileTransfer.download(
uri,
filePath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
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=="
}
}
);
}
config.xml
<access origin="*" />
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
and my manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
The errors Im getting
E/FileTransfer(878): {"target":"\/sdcard\/test.pdf","source":"https:\/\/www.dropbox.com\/s\/27bxw65u4ga5is0\/tes t.pdf","http_status":0,"code":1}
E/FileTransfer(878): java.io.FileNotFoundException:/sdcard/test.pdf: open failed: EACCES (Permission denied)
E/FileTransfer(878): at libcore.io.IoBridge.open(IoBridge.java:416) E/FileTransfer(878): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
E/FileTransfer(878): at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:290)
E/FileTransfer(878): at org.apache.cordova.CordovaResourceApi.openOutputStream(CordovaResourceApi.java:271)
E/FileTransfer(878): at org.apache.cordova.filetransfer.FileTransfer$4.run(FileTransfer.java:711)
I've spent almost 2 days now trying to solve this issue without success.