4

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).

Ivan Verges
  • 595
  • 3
  • 10
  • 25
  • Note that wired Ethernet is not commonly found on Android devices, so it may be that whatever way it has been provided on yours does not have rich or well-thought-out configuration support but instead may only provide basic functionality. – Chris Stratton Feb 11 '14 at 18:14
  • So that means that actually i can just see the state but not turn it on/off until the API's include a wider support for Ethernet? – Ivan Verges Feb 11 '14 at 18:20
  • It means that someone would likely need to be familiar with your unmentioned specific device and Android installation in order to know what you can actually do. – Chris Stratton Feb 11 '14 at 18:21
  • Ok, i get it. I'll keep searching on the net and see if i'm lucky. :) About what i'm using, It's a Chinese Mini-PC, Running Android Jelly Bean 4.2.2. And that's the problem, it's a chinese device, and it's very difficult to find a good support (more than a image download and basic description) for chinese devices. – Ivan Verges Feb 11 '14 at 18:40

3 Answers3

2

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"});
M-Pixel
  • 3,501
  • 2
  • 16
  • 27
Ivan Verges
  • 595
  • 3
  • 10
  • 25
  • In addition to activating the interface with `netcfg`, I had to tell the OS to use _that_ interface for internet access by running `dhcpcd eth0` (thanks to [this Q/A](https://stackoverflow.com/questions/16929957/android-ics-4-1-usb-ethernet-how-to-toggle-ethernet-connectivity-state)). – M-Pixel Jun 13 '21 at 01:39
0

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);
        }
Wais
  • 1,739
  • 1
  • 13
  • 13
  • I already have the wifi toggler (On/Off), i'm talking about the ethernet connection (Connection With RJ45 Cable). Anyway thanks for your response, it's useful for lot of people. – Ivan Verges Feb 11 '14 at 15:35
  • Cannot resolve symbol 'var' ;-P It should be: `ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);` – Kapitein Witbaard Aug 15 '16 at 15:21
0

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:
Wais
  • 1,739
  • 1
  • 13
  • 13
  • Thanks again, but i still findind a way to toogle, i can chech the connected/disconnected state, but not turn it On and Off. I can do it for the Wi-Fi network using the WifiManager, but not with the Ethernet, that's what i'm trying to do. – Ivan Verges Feb 11 '14 at 16:16