- Crate a CronetEngine.Builder with
new CronetEngine.Builder(context)
. - Set envoy URL to the engine:
engineBuilder.setEnvoyUrl("MY_ENVOY_URL")
. - Build an engine by calling
engineBuilder.build()
. - Cast the result to HttpURLConnection type after invoking
engine.openConnection(url)
.
- Create the retrofit client using the retrofit service and build the client.
- While building the retrofit client, use OkHttpClient for the interceptor.
- Create CronetEngine object, set the envoy URL to the engine, and create CronetInterceptor using the engine.
- Add the CronetInterceptor to your OkHttpClient using addInterceptor() method from the OkHttpClient class.
- Create CronetOkHttpCallFactory object using the OkHttpClient and pass this object to the callFactory() method of the retrofit client.
- Now your retrofit client will intercept and create a proxy between your HTTP connection and every network call that the client provides.