Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Method to load a WebView that will receive the real 100% progress of the WebView avoiding fake 100% progress due redirections
private void loadPage() {
WebSettings seetings = mWebView.getSettings();
seetings.setJavaScriptEnabled(true);
seetings.setBuiltInZoomControls(false);
seetings.setSupportZoom(true);
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
mLoadingCount++;
return super.shouldOverrideUrlLoading(view, url);
}
});
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
getActivity().setProgress(progress * 100);
if(progress==100){
if(mLoadingCount ==0 ) {
//WebView 100% loaded
mProgresBar.setVisibility(View.GONE);
}
if(mLoadingCount >0 ) {
mLoadingCount--;
}
}
Log.d(TAG, "Progress: " + progress + "%");
}
});
mWebView.loadUrl(mURL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment