Cordova+Vue APP 安卓自動(dòng)升級(jí)

一、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


? ? ? ? ? ? ? ?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容