From a5b2c11b08791667221fce266c909a46cb8d6054 Mon Sep 17 00:00:00 2001 From: Babar Bashir Date: Fri, 4 Jan 2019 22:00:08 +0500 Subject: [PATCH] Updated depricated http apis. I have updated depricated "BasicHttpParams" http apis to "HttpURLConnection". --- ConnectionService.java | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/ConnectionService.java b/ConnectionService.java index 325064b..35e0820 100644 --- a/ConnectionService.java +++ b/ConnectionService.java @@ -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();