1

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:

  1. how can I access the file directly to launch manually; or
  2. 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;
MikeB
  • 788
  • 1
  • 9
  • 27
  • "how can I access the file directly to launch manually" -- run your app on an emulator, then use DDMS' file manager. Or, from the command line, use `adb run-as` to run commands as the Linux user associated with your app. – CommonsWare Nov 20 '15 at 17:16
  • Tnx. I have tried run-as which generated the following question: http://stackoverflow.com/questions/33830153/adb-run-as-package-listed-but-errors-as-unknown – MikeB Nov 20 '15 at 22:10

0 Answers0