Created
April 26, 2018 09:44
-
-
Save AkshayMoorthy/320d782b702985979c6586d62cd76978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class PicassoTrustAll { | |
private static Picasso mInstance = null; | |
private PicassoTrustAll(Context context) { | |
OkHttpClient.Builder client = new OkHttpClient.Builder(); | |
client.hostnameVerifier(new HostnameVerifier() { | |
@Override | |
public boolean verify(String s, SSLSession sslSession) { | |
return true; | |
} | |
}); | |
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { | |
@Override | |
public void checkClientTrusted( | |
java.security.cert.X509Certificate[] x509Certificates, | |
String s) throws java.security.cert.CertificateException { | |
} | |
@Override | |
public void checkServerTrusted( | |
java.security.cert.X509Certificate[] x509Certificates, | |
String s) throws java.security.cert.CertificateException { | |
} | |
@Override | |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { | |
return new java.security.cert.X509Certificate[] {}; | |
} | |
} }; | |
try { | |
SSLContext sc = SSLContext.getInstance("TLS"); | |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); | |
client.sslSocketFactory(sc.getSocketFactory()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
mInstance = new Picasso.Builder(context) | |
.downloader(new OkHttp3Downloader(client.build())) | |
.listener(new Picasso.Listener() { | |
@Override | |
public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { | |
} | |
}).build(); | |
} | |
public static Picasso getInstance(Context context) { | |
if (mInstance == null) { | |
new PicassoTrustAll(context); | |
} | |
return mInstance; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment