I am trying to debug an app I made, a portion of which downloads an .apk file and then installs it.
function downloadFrom(url, file) {
if (!window.cordova) return Promise.reject(new Error("Not in Cordova"));
var toLocation = "cdvfile://localhost/persistent/Download/" + file;
var transfer = new window.FileTransfer();
console.debug("Downloading file", url, toLocation);
return new Promise(function (resolve, reject) {
transfer.download(url, toLocation, resolve, reject, false, {});
});
}
The download seems executes with no errors BUT I get a parse error when I try to install the .apk with the following:
function openAPK(apk) {
if (!window.cordova) return Promise.reject(new Error("Not in Cordova"));
return new Promise(function (resolve, reject) {
console.debug("Opening APK", apk);
var show = apk.toURL();
console.log("URL used: ", show);
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: apk.toURL(),
type: 'application/vnd.android.package-archive'
}, resolve, reject);
});
}
To confirm the download is not corrupted, I wanted to go the the folder where the file is located, and launch it manually. The url ( apk.toURL() ) looks like:
file:///data/data/org.crosswalkproject.xwalkembed/files/files/Download/My_App.apk
I opened up the file manager on my device (Samsung Galaxy Tab) but cannot find the directory or file ie. Device storage > Android > data > org.crosswalkproject.xwalkembed contains nothing. So:
- how can I access the file directly to launch manually; or
- how can I save the file in the device's Downloads directory?
[SOLVED] changed download location from
var toLocation = "cdvfile://localhost/persistent/" + file;
to
var toLocation = cordova.file.externalDataDirectory + file;