Is Connected To Internet : Connectivity « Network « Android

Home
Android
1.2D Graphics
2.Animation
3.Core Class
4.Database
5.Date Type
6.Development
7.File
8.Game
9.Hardware
10.Media
11.Network
12.Security
13.UI
14.User Event
Android » Network » Connectivity 
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 = (ConnectivityManagerc.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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.