Ivan Verges
Ivan Verges

Reputation: 641

How can i enable/disable the Ethernet connection on Android?

I'm working on Xamarin for Android, and i need to enable/disable the ethernet connection (RJ45 Cable), i've been looking for it from about 3 days and can't find anything that help me out with this.

Does anyone know a way to do it??

Today i found this:

http://developer.oesf.biz/em/developer/reference/durian/android/net/ethernet/EthernetManager.html

But i can't find either Java.Lang.Object nor Android.Net.Ethernet on Xamarin. Even on Eclipse i can't find it and i have the SDK updated and complete (From API 2 to API 19).

Upvotes: 4

Views: 16262

Answers (3)

Ivan Verges
Ivan Verges

Reputation: 641

I found a way to start the ethernet using an internal command, requires Root access, but works.

Java.Lang.Runtime proc = Java.Lang.Runtime.GetRuntime();

proc.Exec(new String[]{"su", "-c", "netcfg eth0 up"});

Upvotes: 2

Wais
Wais

Reputation: 1759

Try

ConnectivityManager.Ethernet;

Class http://developer.android.com/reference/android/net/ConnectivityManager.html

ConnectivityManager Types :

  1. ConnectivityType.Mobile
  2. ConnectivityType.MobileDun:
  3. ConnectivityType.MobileHipri:
  4. ConnectivityType.Bluetooth:
  5. ConnectivityType.Ethernet:
  6. ConnectivityType.Wifi:
  7. ConnectivityType.Wimax:

Upvotes: 0

Wais
Wais

Reputation: 1759

I Think

var connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService); 
var mobileState = connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).GetState();

        if (mobileState != NetworkInfo.State.Connected)
        {
            //set your wifi on
            var mawifi = (WifiManager)GetSystemService(WifiService);
            mawifi.SetWifiEnabled(true);
        }

Upvotes: 0

Related Questions