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
Flowable<String> f = Flowable.just("Hello"); | |
Disposable d1 = f.subscribeWith(new DisposableSubscriber<String>() { … }); | |
Observable<String> o = Observable.just("Hello"); | |
Disposable d2 = o.subscribeWith(new DisposableObserver<String>() { … }); | |
Maybe<String> m = Maybe.just("Hello"); | |
Disposable d3 = m.subscribeWith(new DisposableMaybeObserver<String>() { … }); | |
Single<String> s = Single.just("Hello"); |
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
PicassoTrustAll.getInstance(getApplicationContext()) | |
.load("base_url"+"Your Image Path") | |
.into(ImageView); |
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) { |
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
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); | |
try { | |
clientBuilder.sslSocketFactory(getSSLConfig(context).getSocketFactory()); | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
clientBuilder.hostnameVerifier(new HostnameVerifier() { |
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
private static SSLContext getSSLConfig(Context context) throws CertificateException, IOException, | |
KeyStoreException, NoSuchAlgorithmException, KeyManagementException { | |
// Loading CAs from an InputStream | |
CertificateFactory cf = null; | |
cf = CertificateFactory.getInstance("X.509"); | |
Certificate ca; | |
// I'm using Java7. If you used Java6 close it manually with finally. | |
try (InputStream cert = context.getResources().openRawResource(R.raw.nginxselfsigned)) { |
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
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); | |
//Basic Auth | |
if (!TextUtils.isEmpty(username) | |
&& !TextUtils.isEmpty(password)) { | |
authToken = Credentials.basic(username, password); | |
} | |
//Create a new Interceptor. | |
Interceptor headerAuthorizationInterceptor = new Interceptor() { |
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
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); | |
//Create a new Interceptor. | |
Interceptor headerAuthorizationInterceptor = new Interceptor() { | |
@Override | |
public okhttp3.Response intercept(Chain chain) throws IOException { | |
okhttp3.Request request = chain.request(); | |
Headers headers = request.headers().newBuilder().add("Authorization", authToken).build(); | |
request = request.newBuilder().headers(headers).build(); | |
return chain.proceed(request); |
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
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); | |
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); | |
// set your desired log level | |
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); | |
// add logging as last interceptor | |
clientBuilder.addInterceptor(loggingInterceptor); |