How to implement Stetho for URLConnection in Volley?

So, I recently learned about Stetho and would like to implement it to intercept network requests. However, I cannot find an example of how to do this for URLConnection:

Here is a snippet of my VolleySingleton class.

private RequestQueue getRequestQueue() {
    HurlStack hurlStack = new HurlStack() {
        @Override
        protected HttpURLConnection createConnection(URL url) throws IOException {
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) super.createConnection(url);
            try {
                httpsURLConnection.setSSLSocketFactory(getSSLSocketFactory());
                httpsURLConnection.setHostnameVerifier(getHostnameVerifier());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return httpsURLConnection;
        }
    };

    if(mRequestQueue == null) {
        // this will make sure that this particular instance will last the lifetime of the app
        // getApplicationContext() is key, it keeps you from leaking the Activity or BroadcastReceiver if someone passes one in.
        mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext(), hurlStack);
    }
    return mRequestQueue;
}

According to the doc: If you use HttpURLConnection, you can use StethoURLConnectionManager

But I can’t figure out how to do this after checking the class. Maybe someone has experience on this issue? Many thanks.

Source: https://github.com/facebook/stetho/blob/master/stetho-urlconnection/src/main/java/com/facebook/stetho/urlconnection/StethoURLConnectionManager.java

Source: http://facebook.imtqy.com/stetho/#integrations

+4

Source: https://habr.com/ru/post/1662364/


All Articles