一、Android App?升級(jí)執(zhí)行流程
????????1、獲取本地版本號(hào)
????????2、請(qǐng)求服務(wù)器獲取服務(wù)器版本號(hào)
????????3、本地版本和服務(wù)器版本不一致提示升級(jí),彈窗提示用戶是否更新
????????4、用戶確定升級(jí),調(diào)用文件傳輸方法下載 apk 文件
? ? ? ??? ??downloadApp(){
?? ????????????document.addEventListener('deviceready',?onDeviceReady,?false)
? ? ? ? ? ? ? ??? ??function onDeviceReady()?{
? ? ? ? ? ? ? ? ?? ???window.requestFileSystem(LocalFileSystem.PERSISTENT,?0,?function?(fs)?{
? ? ? ? ? ? ? ? ? ? ? ? let url = 'http://127.0.0.1:8080/test.apk'
? ? ? ? ? ? ? ? ? ? ? ?fs.root.getFile(‘test.apk',?{ create: true,?exclusive: false },
? ? ? ? ? ? ? ? ? ? ? function(fileEntry)?{
? ? ? ? ? ? ? ? ? ? ? ? download(fileEntry,?url)
? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ?})
? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? function download(fileEntry,?uri)?{
? ? ? ? ? ? ? ? ? var fileTransfer = new FileTransfer()
? ? ? ? ? ? ? ? ? fileTransfer.download(uri,?window.cordova.file.externalRootDirectory +?‘test.apk',?function?(entry)?{
? ? ? ? ? ? ? ? ? ? //?alert('文件保存位置: ' + entry.toURL())? ? ??
? ? ? ? ? ? ? window.cordova.plugins.fileOpener2.open(entry.toURL(),?'application/vnd.android.package-archive',?{
? ? ? ? ? ? ? ? ? ? ? error()?{
? ? ? ? ? ? ? ? ? ? ? ? //?console.log('安裝文件打開失敗')
? ? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? ? success: function()?{
? ? ? ? ? ? ? ? ? ? ? ? //?console.log('安裝文件打開成功')
? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? },?function?(error)?{
? ? ? ? ? ? ? ? ? ? alert('error source ' + error.source)
? ? ? ? ? ? ? ? ? },?null,?{
? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? }
? ??????}
????????5、監(jiān)聽下載進(jìn)度
????????6、下載完成打開 Apk 進(jìn)行安裝
二、自動(dòng)升級(jí)?APP?需要的插件
????????1、cordova-plugin-app-version? https://github.com/whiteoctober/cordova-plugin-app-version
????????2、cordova-plugin-file-opener2?https://github.com/pwlin/cordova-plugin-file-opener2
????????3、cordova-plugin-file-transfer? https://github.com/apache/cordova-plugin-file-transfer
????????4、cordova-plugin-file? https://github.com/apache/cordova-plugin-file
? ? ? ? ? ? ? ?