Android - Ethernet - Programmatically
Asked Answered
M

1

9

I am developing an Android app which will be used by custom devices which will have ethernet support (and also wifi).

The app has to enable a settings activity for Ethernet.

Please NOTE that these settings have to be run by the app and not by the Android settings, since the app will be the only thing running on the device and the user will not have access to the Android running in the background.

The user has to be able to:

  1. ENABLE/DISABLE Ethernet
  2. Choose DHCP or STATIC
  3. If choosing STATIC - set IP, gateway

The problem is that I cannot access the android.net.ethernet programmatically and there is no explanation about this issue online.

So if someone has done something like this, please help me get into the right direction.

Morrell answered 14/2, 2014 at 9:14 Comment(8)
I can only provide some links which may help: android.net.ethernet, android ethernet tutorialPhenomenalism
Thanks. I was looking at this already few days ago but it did not help me any further :( since it was done for enterprise desktop ip phones and it used some frameworks i do not have or do not know how to use themMorrell
Same Problem... #21746692Transmissible
Someone wrote a library... Don't know if it works nor how complicated it is... github.com/gxben/aosp-ethernetPhenomenalism
But how can i use that ? Means Should i run that or ? No means of idea regarding how to do with that ?Transmissible
me neither, have no idea how to use thatMorrell
here is a youtube presentation of that tutorial for enterprise desktop ip phone ... it gives some insights youtu.be/LwI2NBq7BWMMorrell
i have made a possible solution for this problem: https://mcmap.net/q/619561/-ethernet-connectivity-through-programmatically-android-rooted-deviceMorrell
R
5

I know it is very late but it might help someone else.

I had some of the requirements you mentioned for my android application. This is how I achieved some of the points

1. ENABLE/DISABLE Ethernet

//Enable Ethernet

 ifconfig eth0 up

//Disable Ethernet

 ifconfig eth0 down

3. If chosen STATIC - set IP, gateway

Fire these commands from java code.

su -c ifconfig eth0 172.19.10.105 netmask 255.255.255.0 up
route add default gw 172.19.10.2 dev eth0

You can execute these commands using following code.

Here command variable is one of the commands mentioned above.

                Process p;
                try {
                    p = Runtime.getRuntime().exec(command);
                    p.waitFor();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

                    String line = "";
                    while ((line = reader.readLine())!= null) {
                        output.append(line + "n");
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
                String response = output.toString();
Radionuclide answered 6/3, 2018 at 10:59 Comment(1)
does this require root?Manisa

© 2022 - 2024 — McMap. All rights reserved.