I'm facing an issue that was reported in this tracker issue back in 2011 and would like to develop a suitable workaround. I would like to display all of an Android device's network interfaces to the user, as well as categorize them by their type and whether or not they are currently active. I'm targeting API 15 at minimum.
As far as I know, there are two ways to get network interface information:
Via the built-in Java
NetworkInterface
class usingNetworkInterface.getNetworkInterfaces()
. This will returnNetworkInterface
objects that contain information like the interface name, all IP addresses associated with the interface, etc. For my device (LG G3), I get interfaces likelo
,wlan0
, andrmnet0
. This also returns information like the IP address, MTU, subnet mask, and broadcast address, which I need.Via the Android API
ConnectivityManager
service usingaConnManager.getAllNetworkInfo()
. This returns about 20NetworkInfo
objects for my device, most are unused, but they include typesMOBILE
,WIFI
,BLUETOOTH
, etc. This doesn't include any network parameters like IP addresses, MTU, etc. as mentioned above.
The issue as explained in the tracker is that there's no built-in way to map the NetworkInfo
to a NetworkInterface
or vice-versa, and I would like to avoid using the interface name to map to the appropriate NetworkInfo
if at all possible.
Since I have a hunch that's not possible, is there a list somewhere of all of the potential network interface names for most vendors? rmnet[0-9]
seems common for devices with Qualcomm baseband processors, and wlan[0-9]
for WiFi, etc.
In the worst case I suppose I could list the interface type as unknown if the interface name doesn't match any common templates. Thanks in advance.
question from:https://stackoverflow.com/questions/31358582/workaround-mapping-between-networkinfo-and-networkinterface