2012-07-12 55 views
5

我們正在開發PhoneGap應用程序,並希望在新版本可用時提供指向新apk文件的鏈接。如何在phonegap下載應用程序

如:

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

這是一個內部的應用程序,所以我們不能把它在Android Market上。它在PhoneGap 1.5中運行良好,但在升級到1.9後停止工作。如果你點擊鏈接沒有任何反應。

我已經添加了我們的服務器cordova.xml(<access origin="http://myserver.com"/>,還試圖<access origin="*"/>)和授銜許可INSTALL_PACKAGES在AndroidManifest.xml

有沒有人一個想法是什麼我失蹤?這是一個權限問題?

+0

「和授銜的權限在AndroidManifest.xml INSTALL_PACKAGES」 - 不,你所要求的INSTALL_PACKAGES權限和系統拒絕你。普通應用程序無法擁有此權限。您必須啓動Package安裝程序並讓用戶按下安裝按鈕才能在股票設備上安裝apk。這不會是你的下載麻煩的原因,但不知道這是什麼。 – FoamyGuy 2012-07-12 16:12:57

+1

我正在嘗試做同樣的事情。任何幫助都會很棒 – 2012-08-19 20:47:20

回答

-1

使用此功能下載文件中的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); 
}; 

}