How does Android use WebView to access https websites?

Source: Internet
Author: User
Tags blank page

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.