Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 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 Reply

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);
            }
        });
    }

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...