Is connected To Ethernet - Android android.net

Android examples for android.net:ConnectivityManager

Description

Is connected To Ethernet

Demo Code

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

public class Main {

  private static boolean connectedToEthernet(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ethInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_ETHERNET);
    if (ethInfo == null) {
      return false;
    }/*w ww  . j  a v a  2  s  .  c  o m*/
    return ethInfo.isConnectedOrConnecting();
  }

}

Related Tutorials