How to force HTTP connection via Wi-Fi instead of cellular in Android?

My application should detect that a device connected to a Wi-Fi network is required, and then program an HTTP request over that Wi-Fi network. I searched, but I did not find any method or class to help me do this.

I was thinking of disabling the cellular network so that the HTTP request would go through the Wi-Fi network, but even so I was not successful. And also, is it possible to enable and disable cellular and Wi-Fi networks programmatically?

+3
source share
3 answers

. , , 3G Wi-Fi ( Wi-Fi , 3G ). - , , , , Wi-Fi, , , . Google Maps - , .

WifiManager , .

+3

setNetworkPrefrence(ConnectivityManager.TYPE_WIFI) ConnectivityManager Android

+2

You can use OkHttp and custom SocketFactory. See https://github.com/square/okhttp/issues/2404 for more details.

0
source

Source: https://habr.com/ru/post/1624834/


All Articles