I am trying to bind to a cellular network on demand (wifi is still running). I have the following code:
override fun onAvailable(network: Network) {
super.onAvailable(network)
Toast.makeText(this@MainActivity, "CELLULAR READY", Toast.LENGTH_SHORT).show()
Log.e("darran", "network info is: " +connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE))
Log.e("darran", "network is metered: " +connectivityManager.isActiveNetworkMetered)
Log.e("darran", "bind is tru: " +connectivityManager.bindProcessToNetwork(network))
Log.e("darran", "bound network is: " +connectivityManager.boundNetworkForProcess)
GlobalScope.launch {
fetchIp(network)
}
}
When I try to bind to the cellular network while wifi is up boundNetworkForProcess
is not the cellular network, but still the wifi network.
If I disable the wifi network this will work every time.
I also have no problem binding immediately between ethernet and wifi. It appears mobile data can not be bound to on demand even if the network is available. How do I immediately bind to the cellular network regardless of the state of the other networks?
The full project is here: