I have implemented a method to check for internet connection
public boolean isInternetWorking() {
boolean success = false;
try {
URL url = new URL("https://google.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(10000);
connection.connect();
success = connection.getResponseCode() == 200;
} catch (IOException e) {
e.printStackTrace();
}
return success;
}
The code works fine. However, I came across many cases where my app would not work properly due to slow internet connection.
Is there any way to show an alert message when the internet connection is slow and the data takes a long time to load?