I want to enable and disable Ethernet in android programatically. I have used following commands which are working on terminal but not on Java code.
ifconfig eth0 down
ifconfig eth0 up
and my code
public String executeCommand() {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec("ifconfig eth0 down");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line);
}
} catch (Exception e) {
Log.d(TAG," exception "+e.toString());
e.printStackTrace();
}
String response = output.toString();
Log.d(TAG," response "+response);
return response;
}
After running this code, I have run cat /sys/class/net/eth0/operstate
command in same code. It is working fine but Ethernet not disable.