I'm trying to reach my server from WiFi or Mobile Data, depending on which interface is answering. The use case is the following : - WiFi is always on. - If the server is not responding through the WiFi (because there is no internet connection for example), then I redirect future requests to the cellular data. - When the connection is back through the WiFi, I redirect next requests to the WiFi.
To achieve this, I wanted to use the ConnectivityManager with TRANSPORT_CELLULAR or TRANSPORT_WIFI. Then it returns a Network object which I can use.
After that I planned to pass the socketFactory from the Network class to the OkHttpClient.
OkHttpClient client = new OkHttpClient.Builder()
.socketFactory(network.getSocketFactory())
.build();
Problem : the server uses a https connection. So I'm building the OkHttpClient using socketSSLFactory, which is build with SSLContext and its method getSocketFactory.
So the question is the following : how can I bind the OkHttpClient to a Network AND to a SSL Socket Factory ?