Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
792 views
in Technique[技术] by (71.8m points)

android - WebView in my app is not loading an HTTPS URL

When I try to load a URL in the WebView it only shows a blank screen. If I load https://www.google.com or https://www.facebook.com it is working fine.

package com.example.hp.cccapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        WebView webb=(WebView)findViewById(R.id.web1);
        webb.setWebViewClient(new WebViewClient());
        //webb.loadUrl("https://www.google.com/");
        webb.loadUrl("https://192.168.2.29/ccc/");

    }
}

Can anyone one suggest me how can I do this so my WebView can handle HTTPS URL?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

i share with you the solution that work for me , it gave me juste the acces to the Web page :

import android.net.http.SslError;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.webkit.GeolocationPermissions;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState)
{

    WebView webView;

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

 webView = (WebView)findViewById(R.id.web1);

    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setBuiltInZoomControls(true);

    webView.getSettings().setGeolocationEnabled(true);
    webView.setWebViewClient(new WebViewClient()
    {

        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler 
       handler, SslError error)
        {
            handler.proceed();
        }
    });

        webView.loadUrl("https://192.168.2.29/ccc/");

        webView.setWebChromeClient(new WebChromeClient()
        {
            @Override
            public void onGeolocationPermissionsShowPrompt(String origin, 
            GeolocationPermissions.Callback callback)
            {
                callback.invoke(origin,true,false);
            }
        });
    }

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...