glide图片加载不出来

2021-11-10  本文已影响0人  莫思闲敏
  1. 首先你确定什么都配置好了,url和imageView没有问题还是加载不出来
  2. 在权限文件中有没有配置 <uses-permission android:name="android.permission.INTERNET"/>
  3. 如果还是不行的话,有没有忽略网络书,在application中的onCreate中配置

 /**
     * 忽略https的证书校验
     * 避免Glide加载https图片报错:
     * javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
     */
    public static void handleSSLHandshake() {
        try {
            TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return new X509Certificate[0];
                }

                @Override
                public void checkClientTrusted(X509Certificate[] certs, String authType) {
                }

                @Override
                public void checkServerTrusted(X509Certificate[] certs, String authType) {
                }
            }};

            SSLContext sc = SSLContext.getInstance("TLS");
            // trustAllCerts信任所有的证书
            sc.init(null, trustAllCerts, new SecureRandom());
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
            HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String hostname, SSLSession session) {
                    return true;
                }
            });
        } catch (Exception ignored) {
        }
    }

上一篇 下一篇

猜你喜欢

热点阅读