check Internet for Context : Context « Core Class « Android






check Internet for Context

     
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

class Main {
  public static boolean checkInternet(Context ctx) {
    NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx
        .getSystemService(Context.CONNECTIVITY_SERVICE))
        .getActiveNetworkInfo();

    if (info == null || !info.isConnected())
      return false;
    if (info.isRoaming())
      return false;
    return true;
  }
}

   
    
    
    
    
  








Related examples in the same category

1.Context.MODE_WORLD_READABLE
2.Returns whether the context is running on the android emulator.
3.add Link
4.performing common form field validation tasks
5.Reads all text from asset with specified path.
6.Context Delete File
7.Context Open file
8.Context.openFileOutput