How to download apk in phonegap application

We are developing the PhoneGap application and want to provide a link to the new apk file when a new version is available.

eg:

<a href="http://myserver.com/myapp.apk">Download</a>

This is an internal application, so we can not put it on the Android market. It worked great with PhoneGap 1.5, but after upgrading to version 1.9 it stopped working. If you click on the link, nothing will happen.

I added our server to cordova.xml (I <access origin="http://myserver.com"/>also tried it <access origin="*"/>) and made a grand permission INSTALL_PACKAGES in AndroidManifest.xml

Does anyone have an idea what I'm missing? Is this a problem with access rights?

+5
source share
1 answer

use this function to download a file in the phone book

function downloadFile(){

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 

    function onFileSystemSuccess(fileSystem) {
        fileSystem.root.getFile(
        "dummy.html", {create: true, exclusive: false}, 
        function gotFileEntry(fileEntry) {
            var sPath = fileEntry.fullPath.replace("dummy.html","");
            var fileTransfer = new FileTransfer();
            fileEntry.remove();

            fileTransfer.download(
                "http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf",
                sPath + "theFile.pdf",
                function(theFile) {
                    console.log("download complete: " + theFile.toURI());
                    showLink(theFile.toURI());
                },
                function(error) {
                    console.log("download error source " + error.source);
                    console.log("download error target " + error.target);
                    console.log("upload error code: " + error.code);
                }
            );
        }, fail);
    }, fail);
};

}

-1
source

All Articles