大熊被骗
大熊被骗
  • 发布:2019-07-19 22:34
  • 更新:2021-06-04 22:17
  • 阅读:3531

uniAPP在web-view 中下载的APP,怎么让安卓手机安装应用

分类:uni-app

uniAPP在web-view 中打开一个外部链接,该链接可以下载一个APP,APP下载了,可是华为手机无法安装,或者提示该应用可以安装APP;

允许安装的权限已经添加

2019-07-19 22:34 负责人:无 分享
已邀请:
大熊被骗

大熊被骗 (作者)

可以啦,  

<template>  
    <view>  
        <web-view :src="url" @message="getMessage"></web-view>  
    </view>  
</template>  

<script>  
    var wv;//计划创建的webview  
    export default {  
       onReady() {  
          console.log('当前环境:' + uni.getSystemInfoSync().platform);//如果是安卓才执行  
          if(uni.getSystemInfoSync().platform == 'android')  
          {  
              var currentWebview = this.$mp.page.$getAppWebview() //获取当前页面的webview对象  
              setTimeout(function() {  
                wv = currentWebview.children()[0]  
                var url222 =  wv.getURL();  
                //console.log('当前网址222: '+url222);  
                // 拦截所有页面跳转,可使用参数拦截.apk的跳转  
                wv.overrideUrlLoading({mode:'reject',match:'.*\.apk.*'}, function(e){  
                    uni.showLoading({  
                        title: '下载中...',  
                        mask: false  
                    });  
                    //console.log('拦截的URL666: '+e.url);  
                    var dtask = plus.downloader.createDownload(e.url, {}, function ( d, status ) {   
                        uni.hideLoading();  
                        uni.showToast({  
                            title: '下载成功...',  
                            mask: false,  
                            duration: 1500    
                        });  
                                      // 下载完成    
                                      if ( status == 200 ) {  
                                          plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{},{},function(error){    
                                              uni.showToast({    
                                                  title: '安装失败',    
                                                  mask: false,    
                                                  duration: 1500    
                                              });    
                                          })    
                                      } else {    
                                           uni.showToast({    
                                              title: '下载失败,请检查您的网络',    
                                              mask: false,    
                                              duration: 1500    
                                           });    
                                      }      
                                  });  
                                dtask.start();  
                    });  
              }, 1000); //如果是页面初始化调用时,需要延时一下  
          }  

        },  
        data(){  
            return {  
                url:'',  
                id:'',  
                banner: {}  
            }  
        },  
        onLoad(option) {  
            // 目前在某些平台参数会被主动 decode,暂时这样处理。  
            try {  
                this.banner = JSON.parse(decodeURIComponent(option.query));  
            } catch (error) {  
                this.banner = JSON.parse(option.query);  
            }  
            this.url = this.banner;  
        },  
        methods:{  
            getMessage(event) {  
                console.log('提示内容: '+JSON.stringify(event.detail.data));  
                uni.showModal({  
                    content: JSON.stringify(event.detail.data),  
                    showCancel: false  
                });  
            }  
        }  
    }  

</script>  

<style>  

</style>  
lxjnoone

lxjnoone

兄弟 牛逼

SMALL

SMALL

大佬,你有加下载进度条吗?

7***@qq.com

7***@qq.com

厉害厉害

5***@qq.com

5***@qq.com

这个可以安装嘛

该问题目前已经被锁定, 无法添加新回复