-1

WebView is now showing but before that a blank white screen is appearing which might be due to loading of the url.

// webview to load url
webView.loadUrl("https://www.google.com/");

I want to add onCompletionListener when the url is fully loaded and webview is ready to display the conent.

  • hope this may help https://stackoverflow.com/questions/3149216/how-to-listen-for-a-webview-finishing-loading-a-url – Basil jose Oct 22 '18 at 07:07
  • Hey, @AdilFarooq If my answer helped you, consider marking it as correct, as this helps future readers and I'd appreciate that. Cheers! :) – PradyumanDixit Nov 04 '18 at 08:25

3 Answers3

1

try this one How can I know that my WebView is loaded 100%?

Or this Url

https://android--code.blogspot.com/2016/03/android-detect-when-webview-finish.html

 // Set a WebViewClient for WebView
            mWebView.setWebViewClient(new WebViewClient(){
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon){
                    // Page loading started
         }

                /*
                    public void onPageFinished (WebView view, String url)
                        Notify the host application that a page has finished loading. This
                        method is called only for main frame. When onPageFinished() is called,
                        the rendering picture may not be updated yet. To get the notification
                        for the new Picture, use onNewPicture(WebView, Picture).

                    Parameters
                        view WebView: The WebView that is initiating the callback.
                        url String: The url of the page.
                */
                @Override
                public void onPageFinished(WebView view, String url){
                    // Page loading finished
                    Toast.makeText(mContext,"Page Loaded.",Toast.LENGTH_SHORT).show();
                }
            });

            // Set a WebChromeClient for WebView
            // Another way to determine when page loading finish
            mWebView.setWebChromeClient(new WebChromeClient(){
                /*
                    public void onProgressChanged (WebView view, int newProgress)
                        Tell the host application the current progress of loading a page.

                    Parameters
                        view WebView: The WebView that initiated the callback.

                        newProgress int: Current page loading progress, represented by an
                            integer between 0 and 100.
                */
                public void onProgressChanged(WebView view, int newProgress){
                    mTextView.setText("Page loading : " + newProgress + "%");

                    if(newProgress == 100){
                        // Page loading finish
                        mTextView.setText("Page Loaded.");
                    }
                }
            });
            // Enable JavaScript
            mWebView.getSettings().setJavaScriptEnabled(true);

            // Load the url in the WebView
            mWebView.loadUrl(mURL);
        }
Jins Lukose
  • 689
  • 6
  • 19
0

You just need to implement WebViewClient and use onPageFinished() as follows:

mWebView.setWebViewClient(new WebViewClient() {

   public void onPageFinished(WebView view, String url) {
        // do what you want
    }
});

Read more about this here.

PradyumanDixit
  • 2,311
  • 2
  • 10
  • 20
0

Just add this one

 webView.setWebViewClient(new WebViewClient() {

    public void onPageFinished(WebView view, String url) {
        // do whatever you want
    }
});

refrance here

Nikunj Paradva
  • 8,208
  • 5
  • 35
  • 50