In Android, WebView can be used to access http and https websites. However, when the https website is accessed by default, if the certificate is not recognized by Android, a blank page is displayed without any prompts, in this case, we must add more configurations.
This method is only applicable to Android 2.1 and later versions.
1 package me. gevin;
2
3 import android.net. http. SslError;
4 import android. OS. Bundle;
5 import android. webkit. SslErrorHandler;
6 import android. webkit. WebView;
7 import android. webkit. WebViewClient;
8
9 public class TestActivity extends Activity {
10
11 WebView wvTest = null;
12
13 @ Override
14 protected void onCreate (Bundle savedInstanceState ){
15 super. onCreate (savedInstanceState );
16 setContentView (R. layout. wvTest );
17
18 wvTest = (WebView) this. findViewById (R. id. wvTest );
19 wvTest. setWebViewClient (new WebViewClient (){
20 public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error ){
21 // handler. cancel (); // default Android Processing Method
22 handler. proceed (); // accept certificates from all websites
23 // handleMessage (Message msg); // perform other processing
24}
25 });
26 wvTest. getSettings (). setJavaScriptEnabled (true );
27 wvTest. getSettings (). setDefaultTextEncodingName ("gb2312 ");
28 wvTest. loadUrl ("https://login.taobao.com /");
29
30}
31
Author: caikezhan