How to download apk within phonegap app

We are developing a PhoneGap app 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>

It is an in-house app so we cannot put it on the android market. It worked fine with PhoneGap 1.5, but after an upgrade to version 1.9 it stopped working. If you click on the link nothing happens.

I've added our server to cordova.xml (<access origin="http://myserver.com"/>, also tried <access origin="*"/> ) and granded the permission INSTALL_PACKAGES in AndroidManifest.xml

Has anyone an idea what i am missing? Is it a permissions issue?

Answers


use this function for downloading file in phonegap

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);
};

}


Need Your Help

Ajax form does not work, security update in browser causing the issue?

ajax security cors same-origin-policy cross-site

here's my problem, I currently have a issue with a form, when the submit button is pressed, the information are not sent to the server. A programmer friend of mine checked and told me it is a secur...

Moment.js - how do I get the number of years since a date, not rounded up?

javascript date momentjs

I'm trying to calculate a person's age using Moment.js, but I'm finding that the otherwise useful fromNow method rounds up the years. For instance, if today is 12/27/2012 and the person's birth dat...