Thursday, May 31, 2018

What is purpose of NetworkManager

This class queries about the state of network connectivity and is responsible also to notify apps when the network state changes. 

Monitor network connections (Wi-Fi, GPRS, UMTS, etc.
Send broadcast intents when network connectivity changes
Attempt to "fail over" to another network when connectivity to a network is lost

Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks
Provide an API that allows applications to request and select networks for their data traffic
void requestNetwork (NetworkRequest request, 
                ConnectivityManager.NetworkCallback networkCallback)
API is the main attraction of this class. 
Request a network to satisfy a set of NetworkCapabilities.

This NetworkRequest will live until released via unregisterNetworkCallback(NetworkCallback) or the calling application exits. A version of the method which takes a timeout is requestNetwork(NetworkRequest, NetworkCallback, int). Status of the request can be followed by listening to the various callbacks described in ConnectivityManager.NetworkCallback. The Network can be used to direct traffic to the network. 

Once the requested network is available, we can bindProcessToNetwork inorder to rooute the traffic via that network. This is especially useful when the WiFi access point is a captive portal. 


References:

https://developer.android.com/reference/android/net/ConnectivityManager#requestNetwork(android.net.NetworkRequest,%20android.net.ConnectivityManager.NetworkCallback)



https://android-developers.googleblog.com/2016/07/connecting-your-app-to-wi-fi-device.html

No comments:

Post a Comment