Back to project page formulize-android.
The source code is released under:
GNU General Public License
If you think the Android project formulize-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package ca.formulize.android.util; /*from w w w . j a va2 s. c o m*/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class ConnectionUtil { /** * Helper function to convert an entire input stream into a String * * @param in * @return String representation of the input stream */ static public String readInputToString(InputStreamReader in) { BufferedReader reader = new BufferedReader(in); StringBuilder stringBuilder = new StringBuilder(); try { // Read server response String line = null; while ((line = reader.readLine()) != null) { stringBuilder.append(line + "\n"); } reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return stringBuilder.toString(); } /** * Check if the user is connected to the Internet. * * @param context The current context of the application * @return True if the user is connected to the Internet, else false */ static public Boolean isOnline(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); } }