Connection Time Out in Android
<p>There are several ways of making HTTP call using Android application. If any one wants to bring a image from http server he/she could use one method to bring the image. On the other hand if a person wants to read JSON or XML for http server response he could use another way to do that. Above two scenarios are just the examples other scenarios might occur. My question is that Is there any standard way through which I can keep check of HttpConnection Timeout. In a particular scenario you can have WIFI or GPRS Connection avaialable but because of its high turnaround time, user experience of my application is getting hampered. How can I keep a check on this issue.</p>

<p>Thanks </p>

<p>Below is code example </p>

<pre><code>public boolean readAndSaveFileFromWeb(String url) {
    byte[] fileRead = null;
    FileOutputStream fos;
    try {
        InputStream is = (InputStream) this.fetch(url);
        if(is!=null){
            fileRead = readBytes(is);
        }else{
            return false;
        }
    } catch (MalformedURLException e) {
        Log.v(TAG, "readAndSaveFileFromWeb Exception: Malformed URL "
                + e.getMessage());
        return false;
    } catch (IOException e) {
        Log.v(TAG, " readAndSaveFileFromWeb Exception:   IOException"
                + e.getMessage());
        return false;
    } catch (Exception e) {
        Log.v(TAG, " readAndSaveFileFromWeb Exception: " + e.getClass());
        return false;
    }
}


public Object fetch(String address) throws MalformedURLException,
        IOException {
    URL url = new URL(address);
    Object content = url.getContent();

    return content;
}
</code></pre>

<p>Now the above code gets the content / response from the address url. In a particular scenario WIFI or GPRS connection is available but the time taken to get data is more if the connection is slow. During this delay .. the application looks hanged though I 'm performing network intensive tasks in different thread than UI thread. This is hampering  user experience a bit.  </p>
