Example usage for android.net ConnectivityManager getNetworkInfo

List of usage examples for android.net ConnectivityManager getNetworkInfo

Introduction

In this page you can find the example usage for android.net ConnectivityManager getNetworkInfo.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
@Nullable
public NetworkInfo getNetworkInfo(@Nullable Network network) 

Source Link

Document

Returns connection status information about a particular Network.

Usage

From source file:org.flakor.androidtool.utils.HttpUtil.java

public int checkNetworkState() {
    int state = NONE_NET;
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    State mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    State wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    // 3G?wifi?2G??????
    if (mobile == State.CONNECTED || mobile == State.CONNECTING) {
        state = MOBILE_NET;//  ww  w .  java  2  s. c  o m
    }
    if (wifi == State.CONNECTED || wifi == State.CONNECTING) {
        state = WIFI_NET;
    }

    return state;

}

From source file:com.cloverstudio.spika.management.ConnectionChangeReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    boolean hasInternetConnection = activeNetInfo != null;
    if (hasInternetConnection) {
        mConnectionChangeBroadcast.putExtra(HAS_INTERNET_CONNECTION, true);
    } else {/*from   w  w w .  ja va2s .  co m*/
        mConnectionChangeBroadcast.putExtra(HAS_INTERNET_CONNECTION, false);
    }
    LocalBroadcastManager.getInstance(context).sendBroadcast(mConnectionChangeBroadcast);
}

From source file:com.example.qrpoll.MainActivity.java

/**
 * sprawdzenie danych pakietowych//from   w w w.j a v  a 2 s  . c om
 * @return
 */
public boolean checkNetwork() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    return ni.isConnected();
}

From source file:com.xenon.greenup.MainActivity.java

public boolean isConnected() {
    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getNetworkInfo(0) != null && cm.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED)
        return true;
    else if (cm.getNetworkInfo(1) != null && cm.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED)
        return true;
    else/*from w  ww  .  j  a  v  a 2  s.c o m*/
        return false;
}

From source file:com.mobeelizer.mobile.android.MobeelizerRealConnectionManager.java

private boolean isConnecting(final ConnectivityManager connectivityManager) {
    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) {
        return connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
    }//from ww w .  j  a va2  s.  c o m
    return connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()
            || connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
}

From source file:com.mobeelizer.mobile.android.MobeelizerRealConnectionManager.java

private boolean isConnected(final ConnectivityManager connectivityManager) {
    if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) == null) {
        return connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
    }/* w w w  .  j a v a2s.  c  o m*/
    return connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()
            || connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
}

From source file:com.ultrafunk.network_info.receiver.MobileDataStatusReceiver.java

private boolean isDataRoaming(Context context) {
    if ((dataState == TelephonyManager.DATA_CONNECTED) && telephonyManager.isNetworkRoaming()) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        return (networkInfo != null) ? networkInfo.isRoaming() : false;
    } else {/* w  ww. j  a va 2 s. c om*/
        return telephonyManager.isNetworkRoaming() && MobileDataUtils.isDataRoaming(context);
    }
}

From source file:com.DPFaragir.DPFUtils.java

public final boolean isInternetActive() {

    // get Connectivity Manager object to check connection
    ConnectivityManager connec = (ConnectivityManager) mContext.getSystemService(mContext.CONNECTIVITY_SERVICE);

    // Check for network connections
    if (connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED
            || connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING
            || connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING
            || connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED) {

        // if connected with internet

        //Toast.makeText(this, " Connected ", Toast.LENGTH_LONG).show();
        return true;

    } else if (connec.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED
            || connec.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED) {

        //Toast.makeText(this, " Not Connected ", Toast.LENGTH_LONG).show();
        return false;
    }//from  w w  w.j  a  v a  2  s . co m
    return false;
}

From source file:com.hkm.Application.appWork.java

public boolean isNetworkOnline() {
    boolean status = false;
    try {//from w w  w . ja v  a2s. co  m
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getNetworkInfo(0);
        if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED) {
            status = true;
        } else {
            netInfo = cm.getNetworkInfo(1);
            if (netInfo != null && netInfo.getState() == NetworkInfo.State.CONNECTED)
                status = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        Tool.trace(getApplicationContext(), e.toString());
        return false;
    }
    return status;
}

From source file:itesm.mx.golpedecalor.SelectGroupActivity.java

public void onClickSincronizar(View v) {
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mMobile = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (mWifi.isConnected() || mMobile.isConnected()) {
        new RequestTask().execute("http://golpedecalor.comoj.com/dbHandler.php");
        Toast.makeText(getApplicationContext(), "Sincronizacion Exitosa", Toast.LENGTH_SHORT).show();
    } else {/*from  www  . ja  va2s.com*/
        Toast.makeText(getApplicationContext(), "No hay conexin a internet", Toast.LENGTH_SHORT).show();
    }

}