美文网首页
Cordova+Vue APP 安卓自动升级

Cordova+Vue APP 安卓自动升级

作者: nicolei | 来源:发表于2020-08-10 15:42 被阅读0次

    一、Android App 升级执行流程

            1、获取本地版本号

            2、请求服务器获取服务器版本号

            3、本地版本和服务器版本不一致提示升级,弹窗提示用户是否更新

            4、用户确定升级,调用文件传输方法下载 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、监听下载进度

            6、下载完成打开 Apk 进行安装

    二、自动升级 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

                   

    相关文章

      网友评论

          本文标题:Cordova+Vue APP 安卓自动升级

          本文链接:https://www.haomeiwen.com/subject/eteqlctx.html