Motivation:

  最近為了替自己的 APP 提供 Paypal 捐贈功能,在 APP 中使用了 webview。但是上架沒多久就被 Google Play 警告這樣實作不安全等,如下圖。

  

Task:

  解決這個問題。

Method:

  研究了一下之後再 stackoverflow 中找到這個註解:

The problem is in your code. When you call handler.proceed(); like that, it effectively removes all the security from your connection. You should remove your onReceivedSslError method. The default implementation will reject insecure connections.

  找到方法之後就是要改 code 了,以下附上我改的地方作為參考。

mWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //設置點擊網頁裡面的鏈接還是在當前的webview裡跳轉
        view.loadUrl(url);
        return true;
    }
    // remove thie override
    /*
    @Override
    public void onReceivedSslError(WebView view,
                                   SslErrorHandler handler, android.net.http.SslError error) {
        //設置webview處理https請求
        handler.proceed();
    }
    */
 });

  如此就解決這個問題了!

  最後附上當時丟出去的 commit

Reference:

  stackoverflow