Example usage for android.content Context CONNECTIVITY_SERVICE

List of usage examples for android.content Context CONNECTIVITY_SERVICE

Introduction

In this page you can find the example usage for android.content Context CONNECTIVITY_SERVICE.

Prototype

String CONNECTIVITY_SERVICE

To view the source code for android.content Context CONNECTIVITY_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.net.ConnectivityManager for handling management of network connections.

Usage

From source file:Main.java

public static boolean isActiveNetworkMobile(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivityManager != null) {
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            return true;
        }//from  w  w w.  jav  a  2  s .c o m
    }
    return false;
}

From source file:Main.java

public static boolean isconnected(Context applicationContext) {

    ConnectivityManager cm = (ConnectivityManager) applicationContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNW = cm.getActiveNetworkInfo();
    boolean isConnected = false;
    if (activeNW != null) {
        isConnected = activeNW.isConnectedOrConnecting();
    }/*from   w  ww . j  a v a2 s  .  c o m*/
    return isConnected;
}

From source file:Main.java

public static boolean isConnectedToInternet(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null)
            for (int i = 0; i < info.length; i++)
                if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }/*from w  ww. j a v a  2  s  .  co m*/
    }
    return false;
}

From source file:Main.java

public static boolean isMobileConnection(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo.State mobile = null;

    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null) {
        mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    }/*from ww  w  . j  av a2 s.c o  m*/

    return (mobile != null && mobile.equals(NetworkInfo.State.CONNECTED));
}

From source file:Main.java

public static boolean isNetConnected(Context context) {
    boolean connected = false;
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    if (networkInfo != null) {
        connected = networkInfo.isConnected();
    }//ww  w.ja v  a 2s  .c  o  m
    return connected;
}

From source file:Main.java

public static boolean isOnline(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    return networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected();
}

From source file:Main.java

public static boolean isNetworkConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isAvailable();
}

From source file:Main.java

public static boolean CheckNet(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (manager == null) {
        return false;
    }// w ww.j ava2s.  co  m
    NetworkInfo networkinfo = manager.getActiveNetworkInfo();
    if (networkinfo == null || !networkinfo.isAvailable()) {
        return false;
    }
    return true;
}

From source file:Main.java

public static boolean isNetworkConncected(Context context) {
    ConnectivityManager connectiveManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectiveManager == null) {
        return false;
    }/*from  w  w w .  j av  a 2s. c  o  m*/
    NetworkInfo networkInfo = connectiveManager.getActiveNetworkInfo();
    if (networkInfo != null) {
        return networkInfo.isAvailable();
    }
    return false;
}

From source file:Main.java

public static final boolean hasWifiConnection(Context context) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return (networkInfo != null && networkInfo.isAvailable());
}