Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data only through mobile data on android phones when wifi is on

Is it possible to programmatically route a request through mobile data even when the wifi is on and connected to the internet?

My app needs to call a service provided by the operator which is only available through mobile data and I don't think it's user-friendly to ask for turning off the wifi.

like image 705
reticent Avatar asked Jul 19 '17 12:07

reticent


People also ask

What happens when both WiFi and mobile data are simultaneously enabled?

Android actually does support simultaneous connection for both 3G and WiFi devices, through an amazing app called SuperSpeed. On LTE phones it will dramatically increase connect speeds.As others have said, when both WiFi and 3G are simultaneously connected, only WiFi will work.

How can I use mobile data while using WiFi?

To do this, swipe down on your notification bar and check that the mobile data toggle is switched on. Or go into “Settings,” tap “Connections,” and “Data Usage” and make sure that mobile data is switched on. Step 2: Connect to a Wi-Fi network. Tap “Settings,” then “Connections”, then “Wi-Fi” and flip the switch on.

Why is my Android phone using mobile data when connected to WiFi?

If your phone detects that the Wi-Fi network stutters, it will switch to the mobile network, so that your phone still consumes mobile data even if it is connected to the Wi-Fi network. To disable Wi-Fi+, go to Settings, search for and access Wi-Fi+, and disable it.

Can I transfer WiFi data to mobile data?

Sharing a connection this way is called tethering or using a hotspot. Some phones can share Wi-Fi connection by tethering. Most Android phones can share mobile data by Wi-Fi, Bluetooth, or USB.


1 Answers

take a look at https://developer.android.com/reference/android/net/ConnectivityManager.html

specifically, it has a function that allows you to do what you want.

 5 Provide an API that allows applications to request and select networks for their data traffic

you request a network, and then setDefaultNetwork( API before 23) or use bindProcessToNetwork for API >= 23 .

you probably want to request a network with int TRANSPORT_CELLULAR capabilities (https://developer.android.com/reference/android/net/NetworkCapabilities.html)

like image 162
Angel Koh Avatar answered Nov 15 '22 06:11

Angel Koh