Is Connected To Internet
//package mhainc.android.O2Spotreba;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;
/**
* @author mhainc
*
*/
class Utils
{
public static void showToastMessage(Context ctx, String msg, int duration )
{
CharSequence text = msg;
if (duration == -1)
{
duration = Toast.LENGTH_SHORT;
}
Toast toast = Toast.makeText(ctx, text, duration);
toast.show();
}
public static void showToastMessage(Context ctx, String msg)
{
showToastMessage(ctx, msg, -1);
}
public static boolean isConnectedToInternet(Context c) {
ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
return (ni != null)&&(ni.isConnected());
}
}
Related examples in the same category