Example usage for android.net ConnectivityManager EXTRA_OTHER_NETWORK_INFO

List of usage examples for android.net ConnectivityManager EXTRA_OTHER_NETWORK_INFO

Introduction

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

Prototype

String EXTRA_OTHER_NETWORK_INFO

To view the source code for android.net ConnectivityManager EXTRA_OTHER_NETWORK_INFO.

Click Source Link

Document

The lookup key for a NetworkInfo object.

Usage

From source file:com.github.luluvise.droid_utils.lib.network.NetworkBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    if (DroidConfig.DEBUG) { // debugging network info
        final NetworkInfo otherNetworkInfo = (NetworkInfo) intent
                .getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
        final String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
        final boolean failover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);
        Log.i(TAG,//from  w w w  .  j av a  2 s.com
                "onReceive(): " + " otherNetworkInfo = "
                        + (otherNetworkInfo == null ? "[none]" : otherNetworkInfo) + ", failover=" + failover
                        + ", reason=" + reason);
    }

    // use EXTRA_NO_CONNECTIVITY to check if there is no connection
    if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) {
        notifyConnectionGone(context);
        return;
    }

    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo netInfo = cm.getActiveNetworkInfo();

    // send local broadcast to notify all registered receivers
    if (netInfo != null && netInfo.isConnected()) { // connection active
        notifyConnectionActive(context, netInfo.getType());
    } else {
        // connection has gone
        notifyConnectionGone(context);
    }
}

From source file:com.github.marcosalis.kraken.utils.network.NetworkBroadcastReceiver.java

private void logNetworkInfo(@Nonnull Intent intent) {
    if (DroidConfig.DEBUG) { // debugging network info
        final NetworkInfo otherNetworkInfo = (NetworkInfo) intent
                .getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
        final String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
        final boolean failover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);
        Log.i(TAG,//from w w  w.java 2  s. c o  m
                "Network info: " + " otherNetworkInfo = "
                        + (otherNetworkInfo == null ? "[none]" : otherNetworkInfo) + ", failover=" + failover
                        + ", reason=" + reason);
    }
}