I am using the following code to iterate through the network interfaces on android:
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
Log.e("get ip: ", inetAddress.getHostAddress());
}
}
}
but if I am connected to a wifi network I only get the wifi IP, where I would expect both the wifi and cellular ip (the phone is on the cell network and got a ip, then I turn on the wifi and suddenly it only reuturns the wifi ip).
So do anyone know what happens? If I use similar code on a iphone I get both cellular and wifi IP.
Yep, android only keeps one of wifi or cellular connected at a time. It looks like ConnectivityManager.requestRouteToHost will allow you to force connections over a particular transport, but personally I’ve never tried it.