-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Great library! I've lost count of the amount of boilerplate I have written for precisely these kinds of connectivity checks.
One thing I have noticed is there is a problem with the way isNetworkConnected works in Lollipop and above. Referring to this code:.The issue is that if you have both WiFi and mobile data switched on, then all network data is transmitted on whatever whichever network has internet connection. For example, take this scenario:
- Say, you have a local, non-internet connected WiFi device (like a Chromecast or other IoT device).
- Your Android is connected to this WiFi Network.
- Your mobile data is also on and that is connected to the internet
In this case, you will be told that you have WiFi connectivity, however if you make any HTTP requests etc, those will go over your mobile data. This may not be what you want. You might want to explicitly communicate with your Chromecast in this example.
The solution is to use the new APIs introduced in ConnectivityManager class in API 21 for this purpose - [requestNetwork](https://developer.android.com/reference/android/net/ConnectivityManager.html#requestNetwork%28android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback%29) and setProcessDefaultNetwork.
More info here.
Having said all of that, I would understand if you do not want to support these complex use cases in this library since it is really meant to be a simple network check annotation lib!