I have followed the instructions of kuester2000\'s answer, but my timeout settings don\'t seem to work.
try
{
int timeout = 3000;
URL myURL = //some
try {
HttpGet httpGet = new HttpGet("your_uri/test.json");
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 5000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 10000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient httpclient = new DefaultHttpClient();
httpGet.setParams(httpParameters);
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
BufferedReader br = null;
if(entity != null) {
Log.i("read", "nube");
br = new BufferedReader(new InputStreamReader(entity.getContent()));
} else {
Log.i("read", "local");
AssetManager am = getApplicationContext().getAssets();
InputStream is = am.open("test.json");
br = new BufferedReader(new InputStreamReader(is));
}
String line;
String texto = "";
while ((line = br.readLine()) != null) {
texto += line;
}
} catch (IOException e) {
e.printStackTrace();
}