4

I would like to assign a static IP to an ethernet card, connected to the Android device via OTG cable. It should be done programmatically, but I can't find any reference regarding ethernet cards in android.

Any ideas?

Thank you

John Nicholas
  • 4,778
  • 4
  • 31
  • 50
Alqueraf
  • 1,148
  • 1
  • 11
  • 26
  • On a stock, non-rooted Android device, there is unlikely to be any support for a USB ethernet adapter, so I expect you will have to implement the entire network stack in userspace within your application, coding against the Android USB host APIs. That's going to be a huge project - but if you get it done, setting a static IP will be a fairly trivial task. – Chris Stratton May 09 '14 at 17:59

1 Answers1

3

If its a rooted device you can try with this

Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", "netcfg eth0 192.168.0.123"});
process.waitFor();

And also you can use ifconfig instead of netcfg.

Charan Pai
  • 2,288
  • 5
  • 32
  • 44