Listen for webview monitoring in Android is loading complete

Source: Internet
Author: User

Previously wrote a method to capture Phoengap's WebView event, mainly in the implementation of cordovainterface activity, in OnMessage according to the first parameter of the message name to determine the WebView load event. However, in fragment, if an activity loads multiple fragment containing webview, it is not possible to determine in OnMessage which WebView's Load event.

After trying, find, or can use setwebviewclient way, to rewrite the corresponding webviewclient Onpagestart and Onpagefinish methods to handle the Load event


[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) {
Logutil.debug ("onreceivederror" + URL);
Super.onreceivederror (view, ErrorCode, description, Failingurl);
Progressbar.setvisibility (View.gone);
Errorview.setvisibility (view.visible);
}
};
Webview.setwebviewclient (cordovawebviewclient);

Webview.loadurl (URL);

Listen for webview monitoring in Android is loading complete

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.