What should I do so that the SSL error message does not appear or at least only appears once

0

In my WebView I am uploading websites that use security certificate, but to upload an APK to playstore a dialog box must be managed which indicates to the user if he wants to proceed or cancel the loading of the site, for which it is used a WebViewClient and the onReceivedSslError method is overwritten, if the site is safe as it can be done so that the error is not shown or at least only appears the first time even if the app's cache is cleared since this message seems to alert about a problem to the user and if you select cancel, you will not be able to see the contents of the website. In the cases of the switch there are 4 options for an error message and one default, as it could be on that side and that allows loading the page without the message?

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View v = inflater.inflate(R.layout.fragment_noticias, container, false);

    WebView view=(WebView) v.findViewById(R.id.wv_noticias);
    view.getSettings().setJavaScriptEnabled(true);
    view.setWebViewClient(new WebViewClient());// Agregamos un WebViewCliente, esto permite que se sigan ejecutando los links dentro de este WebView
    view.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
            String message = "";
            switch (error.getPrimaryError()) {
                case SslError.SSL_UNTRUSTED:
                    message = "The certificate authority is not trusted.";
                    break;
                case SslError.SSL_EXPIRED:
                    message = "The certificate has expired.";
                    break;
                case SslError.SSL_IDMISMATCH:
                    message = "The certificate Hostname mismatch.";
                    break;
                case SslError.SSL_NOTYETVALID:
                    message = "The certificate is not yet valid.";
                    break;
                default:
                    break;
            }
            message += "\"SSL Certificate Error\" Deseas continuar?";

            builder.setTitle("SSL Certificate Error");
            builder.setMessage(message);
            builder.setPositiveButton("continuar", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handler.proceed();
                }
            });
            builder.setNegativeButton("cancelar", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    handler.cancel();
                }
            });
            builder.create().show();
        }
    });
    //view.loadUrl(url);
    /****************************************/
    if (isOnline(getActivity())) {
        String url="https://www.uniagustiniana.edu.co/Noticias/";
        view.loadUrl(url);
        //Toast.makeText(getActivity(),"SI hay conexión!",Toast.LENGTH_SHORT).show();
    } else {
        view.loadUrl("file:///android_asset/html/pagina_error.html");
        Toast.makeText(getActivity(),"NO hay conexión!",Toast.LENGTH_SHORT).show();
    }

    return v;
}

    
asked by Ivan Alfredo 30.08.2018 в 17:43
source

0 answers