How to use Stetho with Volley?

妖精的绣舞 提交于 2019-11-30 09:32:42

Add this file in project Updated OkHttpStack

and

Try this:

Stetho.initializeWithDefaults(this);
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
mRequestQueue = Volley.newRequestQueue(getApplicationContext(), new OkHttpStack(client));

with following dependencies:

implementation 'com.facebook.stetho:stetho-okhttp:(insert latest version)'
implementation 'com.squareup.okhttp3:okhttp:(insert latest version)'

the answer of @Sabeeh is correct, only update your libraries in your gradle

compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.facebook.stetho:stetho-okhttp:1.3.1'
compile 'com.facebook.stetho:stetho-urlconnection:1.3.1'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.mcxiaoke.volley:library:1.0.19'

Now in your Application class of your project add this

    Stetho.initializeWithDefaults(this);

    OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.networkInterceptors().add(new StethoInterceptor());
    mRequestQueue = Volley.newRequestQueue(this, new OkHttpStack(okHttpClient));

Import your libraries and yet we will see an error with OkHttpStack(okHttpClient) so you only need to copy this code provided by @bryanstern Class OkHttpStack so create the file import and enjoy it

If you want to use Stetho for volley without using OkHttp stack.

Please refer this link. Stetho for Volley

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!