WebView.getUrl () returns null

I have a problem with Webview. I program my own WebChromeClient class by overriding the onProgressChanged method because I want to show the page when it finishes loading, and then to hide the splash screen. Since I just want this to happen with a specific URL, I am comparing the actual WebView URL with a specific string, but there is a problem, I get a null pointer when the webview.getUrl () method is called, and my application ends. This is the code:

private class MyWebChromeClient extends WebChromeClient {
    @Override
    public void onProgressChanged (WebView webview, int newProgress) {
        super.onProgressChanged(webview,newProgress);
        if(webview.equals(w1) && newProgress == 100 && webview.getUrl().startsWith("https://ssl.facebook.com/login.php")) { 
            webview.setVisibility(WebView.VISIBLE);
            ImageView imageview = (ImageView)findViewById(R.id.ivsplash);
            imageview.setVisibility(ImageView.GONE);
            ProgressBar progressbar = (ProgressBar)findViewById(R.id.pbsplash);
            progressbar.setVisibility(ProgressBar.GONE);
        }
    }
}

I do this so that the web view takes three or four seconds to make the page, but it does not work. The code I used earlier:

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView webview, String url) {
        super.shouldOverrideUrlLoading(webview, url);
        webview.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView webview, String url) {
        if(url.startsWith("https://ssl.facebook.com/login.php")) {
            webview.setVisibility(WebView.VISIBLE);
            ImageView imageview = (ImageView)findViewById(R.id.ivsplash);
            imageview.setVisibility(ImageView.GONE);
            ProgressBar progressbar = (ProgressBar)findViewById(R.id.pbsplash);
            progressbar.setVisibility(ProgressBar.GONE);
        }
    }
}

thank

+3
source share
1

, WebChromeClient, ,

WebViewClient onLoadResource, onReceivedError onPageFinished

,

onLoadResource     
 mwebview.setVisibility(View.GONE);


onReceivedError
mwebview.setVisibility(View.VISIBLE);

onPageFinished
mwebview.setVisibility(View.VISIBLE);

XML - GONE

android:visibility="gone"

Facebook .

+2

Source: https://habr.com/ru/post/1753156/


All Articles