凯发K8_凯发K8平台_凯发K8网址_网易新闻
全国免费咨询热线

区块链技术

程序员

当前位置:主页 > 程序员 >

联系我们

CONTACT

地址:
电话:
传真:
邮箱:

Android中监听Phonegap的webview的start,finish等事件

2019-01-18

之前写过一篇捕获Phoengap的webview事件的方法,主要是在实现了CordovaInterface的Activity中,  在onMessage中根据第一个参数的message name来判断webview的加载事件。不过如果是在Fragment中,一个Activity加载了多个包含了WebView的fragment的话,就无法在onMessage中判断到底是哪个WebView的加载事件。

经过尝试,发现,还是可以使用setWebViewClient的方式来,来重写WebViewClient的对应的onPageStart和onPageFinish等方法来处理加载事件


[java]
CordovaWebView webView = (CordovaWebView)findViewById(R.id.webView); 

 CordovaWebView webView = (CordovaWebView)findViewById(R.id.webView);[java] view plaincopyprint?CordovaInterface cordovaInterface = (CordovaInterface) context; 
 
       CordovaWebViewClient cordovaWebViewClient = new CordovaWebViewClient(cordovaInterface, webView) { 
           @Override 
           public void onPageStarted(WebView view, String url, Bitmap favicon) { 
 
               LogUtil.debug("onPageStarted " + url); 
               super.onPageStarted(view, url, favicon); 
               progressBar.setVisibility(View.VISIBLE); 
           } 
 
           @Override 
           public void onPageFinished(WebView view, String url) { 
               LogUtil.debug("onPageFinished " + url); 
               super.onPageFinished(view, url); 
               progressBar.setVisibility(View.GONE); 
           } 
 
           @Override 
           public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
               LogUtil.debug("onReceivedError " + url); 
               super.onReceivedError(view, errorCode, description, failingUrl); 
               progressBar.setVisibility(View.GONE); 
               errorView.setVisibility(View.VISIBLE); 
           } 
       }; 
       webView.setWebViewClient(cordovaWebViewClient); 
 
       webView.loadUrl(url); 

 CordovaInterface cordovaInterface = (CordovaInterface) context;

        CordovaWebViewClient cordovaWebViewClient = new CordovaWebViewClient(cordovaInterface, webView) {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {

                LogUtil.debug("onPageStarted " + url);
                super.onPageStarted(view, url, favicon);
                progressBar.setVisibility(View.VISIBLE);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                LogUtil.debug("onPageFinished " + url);
                super.onPageFinished(view, url);
                progressBar.setVisibility(View.GONE);
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
           &nbsAAAAAAA;   LogUtil.debug("onReceivedError " + url);
                super.onReceivedError(view, errorCode, description, failingUrl);
                progressBar.setVisibility(View.GONE);
                errorView.setVisibility(View.VISIBLE);
            }
        };
        webView.setWebViewClient(cordovaWebViewClient);

        webView.loadUrl(url);

 

http://www.bkjia.com/Androidjc/538855.htmlwww.bkjia.comtruehttp://www.bkjia.com/Androidjc/538855.htmlTechArticle之前写过一篇捕获Phoengap的webview事件的方法,主要是在实现了CordovaInterface的Activity中, 在onMessage中根据第一个参数的message name来判断webview的...

本文源自: 凯发K8

上一篇:Android 异步更新UI----AsyncTask

下一篇:没有了

【返回列表】

Copyright 2018 凯发K8_凯发K8平台_凯发K8网址_网易新闻 版权所有

友情链接: