First Approach i
Make sure that you have set TLS enabled from the server side.
Do you have used Okhttp library ? It is very good library for network calls. You can handle this exception it that also.
I had similar issue and i have managed it with this :
public static OkHttpClient getHttpClientForFile() {
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.tlsVersions(TlsVersion.TLS_1_0)
.cipherSuites(
CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
CipherSuite.TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA,
CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA)
.build();
return new OkHttpClient.Builder()
.connectTimeout(2, TimeUnit.MINUTES)
.writeTimeout(2, TimeUnit.MINUTES)
.readTimeout(3, TimeUnit.MINUTES)
.connectionSpecs(Collections.singletonList(spec))
.protocols(Arrays.asList(Protocol.HTTP_1_1))
.build();
}
I don't know whether it is good or not, but it is working for me.
The class you have used SSLSocketFactory
may produce error after publishing app on play store or play store may give you warning to change your code.
You can find Okhttp
library from https://github.com/square/okhttp.
I have faced the same issue, same javax.net.ssl.SSLHandshakeException
is throwing at the time of API call.
but in my case, the following was the issue
my device
was connected
to the wifi
but wifi router was not
having the internet
connection and then the exception
was thrown