Workaround mapping between NetworkInfo and NetworkInterface

Since API 21, you can use LinkProperties to get a NetworkInterface object out of a Network network object:

ConnectivityManager manager = getSystemService(ConnectivityManager.class);
LinkProperties prop = manager.getLinkProperties(network);    
NetworkInterface iface = NetworkInterface.getByName(prop.getInterfaceName());

However, although getAllNetworks() is supposed to replace getAllNetworkInfo() (the former, introduced in API 21, has deprecated the latter in API 23), as of Android 6.0.1, it does not. getAllNetworks() does not list all networks (see SO Q#33374766). Looks like a bug.

Alternatively, in order to inform the user about the status of all network connections, a set of callbacks may be registered for each transport type available in NetworkCapabilities (i.e. TRANSPORT_CELLULAR, TRANSPORT_WIFI, TRANSPORT_ETHERNET, TRANSPORT_BLUETOOTH & TRANSPORT_VPN)
using registerNetworkCallback.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)