Skip to content

Commit

Permalink
Fix issue dscnitrourkela#38
Browse files Browse the repository at this point in the history
Add a function to check the internet availability and use it before make any network calls
  • Loading branch information
ferquies authored Oct 3, 2019
1 parent 8f680df commit e9a3aa8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scp/android/app/src/main/kotlin/in/ac/nitrkl/scp/FaqActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ private class SearchFetch extends AsyncTask {

@Override
protected String doInBackground(Object[] objects) {
if (!isInternetAvailable()) {
return null;
}

if (searchText.equalsIgnoreCase("")) {
try {
result = client.prepareSearch(Constants.APP_NAME, Constants.QUERY)
Expand Down Expand Up @@ -214,4 +218,14 @@ protected void onPostExecute(Object o) {
}
}
}

public boolean isInternetAvailable() {
try {
InetAddress ipAddr = InetAddress.getByName("google.com");
return !ipAddr.equals("");

} catch (Exception e) {
return false;
}
}
}

0 comments on commit e9a3aa8

Please sign in to comment.