From e9a3aa849bc2a61b6dd47a06fe12e6e968c14f8d Mon Sep 17 00:00:00 2001 From: Fernando Esquitino Date: Thu, 3 Oct 2019 20:22:36 +0200 Subject: [PATCH] Fix issue #38 Add a function to check the internet availability and use it before make any network calls --- .../main/kotlin/in/ac/nitrkl/scp/FaqActivity.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scp/android/app/src/main/kotlin/in/ac/nitrkl/scp/FaqActivity.java b/scp/android/app/src/main/kotlin/in/ac/nitrkl/scp/FaqActivity.java index 8f2cd3d..52ea3bd 100644 --- a/scp/android/app/src/main/kotlin/in/ac/nitrkl/scp/FaqActivity.java +++ b/scp/android/app/src/main/kotlin/in/ac/nitrkl/scp/FaqActivity.java @@ -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) @@ -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; + } + } }