Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Interfacing with Ethernet Connection

Tags:

android

On My Android device i have both Ethernet and Wifi Network connections.
What i wan to implement is I want to check if Wifi and Ethernet both the connections are Active at the same time then I wan to disable the Wifi Network and Keep Ethernet Connection ON.

I am using android WifiManager and BroadcastReceiver android.net.conn.CONNECTIVITY_CHANGE for Checking Wifi state Connected/Disconnected and also to Enabling/Disabling the Wifi Network.

But I am not able to check the Ethernet Connection State and also I am not able to Enable/Disable the Ethernet Connection.

For Checking the Ethernet connection sate I am reading system file '/sys/class/net/eth0' which is returning me Correct Ethernet State. But for Enabling/Disabling Ethernet I am not able to figure it out how to do it.

I have Ethernet Connection Options in the Settings menu provided by the Android from where we can configure Ethernet connection of the device.

In the ConnectivityManager there is an API getActiveNetworkInfo which only returns the currently connection network interface, But I want to retrieve the list of all the Connected Interfaces from where we can connect to internet.

Is there any service running on Android that can give me Access to Enable/Disable Ethernet connection and also API to get the Ethernet connection state?

Thanks.

like image 961
User7723337 Avatar asked Jan 19 '12 10:01

User7723337


People also ask

Can I use my phone as an Ethernet router?

Under the 'Wireless and networks' heading, select Tethering and mobile hotspot and then select USB tethering. The network icon in the taskbar should display a wired connection when it is successful. Congratulations, you have now successfully used your Android smartphone as a modem.


1 Answers

One Way of archiving it,
Current Ethernet state of Android Device is updated in the file /sys/class/net/eth0/operstate by Android operating system. We need to read this file for getting the state.

File will contain string UP if Ethernet is up else string DOWN if Ethernet is down.

I tried this way and it is working for me.

But not sure if it will work on all the devices with all the Android versions.

like image 73
User7723337 Avatar answered Oct 17 '22 17:10

User7723337