Glide不同版本,自定义okhttp的方法不同
这里仅仅提供两个版本 v3.7.0 和v 4.12.0
- implementation 'com.github.bumptech.glide:glide:3.7.0'
- implementation 'com.github.bumptech.glide:okhttp-integration:1.3.1'
- public class AppStart extends Application {
-
- @Override
- public void onCreate() {
- super.onCreate();
- // Glide3.7.0 okhttp-integration:1.3.1
- Glide.get(this).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(getOkHttpClient()));
- }
-
- public OkHttpClient getOkHttpClient () {
- try {
- // Create a trust manager that does not validate certificate chains
- final TrustManager[] trustAllCerts = new TrustManager[]{
- new X509TrustManager() {
- @Override
- public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) {
- }
-
-
- @Override
- public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
- }
-
- @Override
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- X509Certificate[] x509Certificates = new X509Certificate[0];
- return x509Certificates;
- }
- }
- };
-
- // Install the all-trusting trust manager
- final SSLContext sslContext = SSLContext.getInstance("SSL");
- sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
-
- // Create an ssl socket factory with our all-trusting manager
- final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
- OkHttpClient okHttpClient = new OkHttpClient();
- okHttpClient.setSslSocketFactory(sslSocketFactory);
- okHttpClient.setProtocols(Arrays.asList(Protocol.HTTP_1_1));
- okHttpClient.setHostnameVerifier((hostname, session) -> true);
- return okHttpClient;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
- public class MainActivity extends AppCompatActivity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- ImageView imageView=findViewById(R.id.iv_logo);
-
- String path="";
- Glide.with(this).load(path).into(imageView);
- }
- }
传送门 https://gitee.com/Pino_W/glide3.7_custom_okhttp.git