对于你们来说,用科尔多瓦3+,像维拉的一个类似的解决方案是可能的:
因此,我们首先要下载.apk文件。我们需要这个文件传输插件。 你可以用下面的命令来安装它:
phonegap local plugin add org.apache.cordova.file-transfer
其次,我们需要另一个插件启动webintent。如果有更新,此webintent会提示用户。你可以用下面的命令来安装它:
phonegap local plugin add https://github.com/Initsogar/cordova-webintent.git
然后,您可以使用此功能2在你的代码下载apk文件并提示用户是否 有应用程序的更新:
/*
* Uses the filetransfer plugin
*/
function downloadApkAndroid(data) {
var fileURL = "cdvfile://localhost/persistent/CegekaMon.apk";
var fileTransfer = new FileTransfer();
var uri = encodeURI(data.android);
fileTransfer.download(
uri,
fileURL,
function (entry) {
console.log("download complete: " + entry.fullPath);
promptForUpdateAndroid(entry);
},
function (error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
}
);
}
/*
* Uses the borismus webintent plugin
*/
function promptForUpdateAndroid(entry) {
window.plugins.webintent.startActivity({
action: window.plugins.webintent.ACTION_VIEW,
url: entry.toURL(),
type: 'application/vnd.android.package-archive'
},
function() {
},
function() {
alert('Failed to open URL via Android Intent.');
console.log("Failed to open URL via Android Intent. URL: " + entry.fullPath);
}
);
}
安装后使用phonegap apk如何自动启动apk?是否有任何特定的方法在fileapi或webintent插件请让我知道 – nida 2013-10-22 04:54:58
我想从http://download.com/update/myapp.apk下载更新。那么代码是什么?请帮忙。 – 2015-08-06 04:45:19