2

How can i catch the timeout in OkHTTP? Is it "called" in the onFailure method?

I would like to handle the situation in which i have bad internet connection. In case of timeout i have to enable some buttons to allow the user to try again.

// Get a handler that can be used to post to the main thread
    client.newCall(request).enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
            hideDialog();
            e.printStackTrace();

            // handle timeouts here, enable buttons...
        }

1 Answers1

-2

You can increase timeout for connection and response for your request. Use following code,

client.setConnectTimeout(15, TimeUnit.SECONDS); // connect timeout
client.setReadTimeout(15, TimeUnit.SECONDS);    // socket timeout