3

I am unable to set timeout to retrofit. The code below does not work with picasso . I get a blank screen and the data and image does not load. How can I fix it with gradle:

compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'

COde:

    final OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.setReadTimeout(60, TimeUnit.SECONDS);
    okHttpClient.setConnectTimeout(60, TimeUnit.SECONDS);


        RestAdapter restAdapter = new RestAdapter.Builder()
.setClient(new OkClient(okHttpClient))
          .setEndpoint(URL).build();                                     
        myapi myapi_rest = restAdapter.create(myapi.class);
        myapi_rest.my_call(
                sno,
                new Callback<Response>() {

                    @Override
                    public void success(Response result, Response response) {


                    }

                    @Override
                    public void failure(RetrofitError error) {
                        // Log.i("Failure", "Error"+error.getMessage());

                    }
                });

Gradle:

compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.squareup.retrofit:retrofit:1.9.0'


    compile "com.squareup.okhttp:okhttp:1.6.0"
    compile "com.squareup.okhttp:okhttp-urlconnection:1.6.0"
jason
  • 3,932
  • 11
  • 52
  • 123
  • Are you trying to accomplish something like this http://stackoverflow.com/a/26941180/2264234 – SemaphoreMetaphor Jan 19 '16 at 19:55
  • @SemaphoreMetaphor Not in picasso but in retrofit .Basically I want to increase timeout in retrofit .But I have library conflict between okhttp and picasso and retrofit .I would like to know which 3 lib versions can be compiled together ? – jason Jan 19 '16 at 20:05
  • That's a **really** outdated version of `okhttp`. Why? You have to set the timeout in `OkHttpClient`, by the way. – EpicPandaForce Jan 19 '16 at 21:34
  • @EpicPandaForce Can you share updated version where retrofit,picasso and okhttp are working together which has timeout? – jason Jan 20 '16 at 06:52

1 Answers1

1

To use your OkHttpClient with Picasso, you need to use the following code.

// Create the downloader for Picasso to use
OkHttpDownloader downloader = new OkHttpDownloader(okHttpClient);
Picasso picasso = new Picasso.Builder(context).downloader(downloader).build();

Specify the OkHttpClient for which you specified the Timeouts.

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
  • I don't want to use with picasso only retrofit. But there is a conflict between all the gradle compile versions as I had mentioned above. How can I use okhttp with retrofit and which version should all 3 versions be in to work smoothly? – jason Jan 20 '16 at 14:05
  • 1
    Added : compile 'com.squareup.retrofit:retrofit:1.9.0' compile 'com.squareup.okhttp:okhttp:2.7.0' compile 'com.squareup.picasso:picasso:2.5.2' – jason Jan 21 '16 at 12:09
  • OkHttpDownloader object is not taking okHttpClient object it takes picasso object. I m using 'com.squareup.picasso:picasso:2.5.2' library. – Rohit Bandil Jan 19 '17 at 11:39
  • Maybe this has changed with OkHttp3 – EpicPandaForce Jan 19 '17 at 11:44