How to implement a test that checks the reliability of the Internet connection

I am working on a project that should test some features of androids and mobile networks. one of them is to check the reliability of the Internet connection, so that I must first check the Internet connection, and then check the reliability

Is there any algorithm or library to find out the reliability of the Internet connection

+7
android internet-connection
source share
1 answer

Perhaps you can send a request to a well-known site to check if the Internet connection is enough to return with a response at a given time.

public boolean checkInternet(){ ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); if (netInfo != null && netInfo.isConnected()) try { URL url = new URL("http://www.google.com"); HttpURLConnection urlc = (HttpURLConnection) url .openConnection(); urlc.setConnectTimeout(3000); urlc.connect(); if (urlc.getResponseCode() == 200) { // Means response is available within 3 seconds // So, return true or do something else. return true; } } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } 
0
source share

All Articles