Is Connected To Internet : Connectivity « Network « Android






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

1.is Network Available
2.System InetAddress
3.is Net Connected
4.Connectivity Tester
5.Is Android connected to your server
6.Is connected