Android Webview网址没有加载

时间:2016-03-18 23:34:07

标签: android android-webview

很少有网址未在网页浏览中加载。请检查代码。如果我加载谷歌它正确加载。任何方案? URL浏览器中的URL负载正确。

此处此网址(以及其他一些网址)未加载wv.loadUrl(“http://resident.uidai.net.in/get-enroled”); 相反,如果谷歌加载它正确加载。我怎么能强行加载这个网址?

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_home, container, false);
    progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1);
    wv = (WebView) rootView.findViewById(R.id.wvHome);
    wv.getSettings().setSupportZoom(true);
    wv.getSettings().setBuiltInZoomControls(true);
    wv.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    wv.setScrollbarFadingEnabled(true);
    wv.getSettings().setLoadsImagesAutomatically(true);
    WebSettings webSettings = wv.getSettings();
    webSettings.setJavaScriptEnabled(true);

    wv.setWebViewClient(new WebViewClient());
    try {
        wv.loadUrl("http://resident.uidai.net.in/get-enroled");
        //wv.loadUrl("http://eaadhaar.uidai.gov.in");
    }
    catch (Exception e)
    {
        wv.loadUrl("http://google.com");
    }
    // Inflate the layout for this fragment
    return rootView;
}

private class HelloWebViewClient extends WebViewClient{


    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView webView, String url)
    {
        webView.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

        progressBar.setVisibility(view.GONE);
    }
    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed(); // Ignore SSL certificate errors
    }

}

1 个答案:

答案 0 :(得分:0)

第一。将http更改为https

第二。更改wv.setWebViewClient(new HelloWebViewClient());

第三。覆盖以下

private class HelloWebViewClient extends WebViewClient {


@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
    // TODO Auto-generated method stub
    super.onPageStarted(view, url, favicon);
}

@Override
public boolean shouldOverrideUrlLoading(WebView webView, String url) {
    webView.loadUrl(url);
    return true;
}

@Override
public void onPageFinished(WebView view, String url) {
    // TODO Auto-generated method stub
    super.onPageFinished(view, url);

    progressBar.setVisibility(view.GONE);
}

@SuppressLint("NewApi")
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
    handler.proceed(); // Ignore SSL certificate errors
}

}