How to bind a socket connection intent?

In android ... Given the set of active sockets (<10), My broadcast receiver receives the intention from the ConnectivityManager that the connection status has changed. How to connect intention with broken sockets?

I can get NetworkInfo with the intention.

final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo netinfo = ConnectivityManagerCompat.getNetworkInfoFromBroadcast(cm, aIntent); 

This gives me an interface type. I can also use a socket to get NetworkInterface.

 final InetAddress sourceAddr = socket.getLocalAddress(); final NetworkInterface ninterface = NetworkInterface.getByInetAddress(sourceAddr); 

But I do not see the opportunity to come from here.

Is there a way to get NetworkInfo associated with a socket?

I am considering manually building a mapping between interface names and network types. This mapping will load upon initialization. This is basically what I do visually when I run the ip or netstat command.

+4
source share

All Articles