Http Get using Android HttpURLConnection

Try getting the input stream from this you can then get the text data as so:- URL url; HttpURLConnection urlConnection = null; try { url = new URL(“http://www.mysite.se/index.asp?data=99”); urlConnection = (HttpURLConnection) url .openConnection(); InputStream in = urlConnection.getInputStream(); InputStreamReader isw = new InputStreamReader(in); int data = isw.read(); while (data != -1) { char current = (char) … Read more

Detect if Android device has Internet connection

You are right. The code you’ve provided only checks if there is a network connection. The best way to check if there is an active Internet connection is to try and connect to a known server via http. public static boolean hasActiveInternetConnection(Context context) { if (isNetworkAvailable(context)) { try { HttpURLConnection urlc = (HttpURLConnection) (new URL(“http://www.google.com”).openConnection()); … Read more

Detect whether there is an Internet connection available on Android [duplicate]

The getActiveNetworkInfo() method of ConnectivityManager returns a NetworkInfo instance representing the first connected network interface it can find or null if none of the interfaces are connected. Checking if this method returns null should be enough to tell if an internet connection is available or not. private boolean isNetworkAvailable() { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); … Read more