Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions ConnectionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,17 @@ public void onDestroy() {
}

private boolean isNetworkAvailable(){
HttpGet httpGet = new HttpGet(url_ping);
HttpParams httpParameters = new BasicHttpParams();

int timeoutConnection = 5000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);

int timeoutSocket = 7000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
try{
httpClient.execute(httpGet);
mConnectionServiceCallback.hasInternetConnection();
return true;
}
catch(ClientProtocolException e){
e.printStackTrace();
}
catch(IOException e){
try {
HttpURLConnection urlc = (HttpURLConnection) (new URL(url_ping).openConnection());
urlc.setRequestProperty("User-Agent", "Test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(1500);
urlc.connect();
if ((urlc.getResponseCode() == 200)) {
mConnectionServiceCallback.hasInternetConnection();
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
mConnectionServiceCallback.hasNoInternetConnection();
Expand Down