Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Force data to be sent over radio vs WiFi

Is it possible to force an Android application to use only the mobile radio connection (3g/4g/etc), disallowing the use of WiFi?

I think I want to use a HIPRI connection: (ex: WIFI turned on, use HIPRI 3G): http://groups.google.com/group/android-developers/browse_thread/thread/d41f85505484d29b

like image 567
wuntee Avatar asked May 04 '11 12:05

wuntee


People also ask

How do I get my phone to use data instead of Wi-Fi?

The same setting on Android phones can be found in the Connections area of the Settings app. Go to the WiFi settings, tap the three dots in the corner to find the advanced settings menu, and then turn off the toggle that says "Switch to mobile data."

How do I force an app to use Wi-Fi only on Android?

For instance, to limit mobile data use for an app, tap the cellular data icon to its extreme right. Otherwise, tap the Wi-Fi icon next to it to restrict the app from running on a Wi-Fi network. Select both icons to stop an app from using data at all.

Can I turn on Wi-Fi and mobile data at the same time?

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.


3 Answers

I don't believe you can "force" the connection path without explicitly turning off the Wi-Fi radio temporarily (not recommended). However, you could try setting the network preference during the period you want this to occur:

ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
//Prefer mobile over wifi
cm.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);

//Do your work

//Remove your preference
cm.setNetworkPreference(ConnectivityManager.DEFAULT_NETWORK_PREFERENCE);

Hope that Helps!

like image 130
devunwired Avatar answered Oct 20 '22 10:10

devunwired


In Android 2.2 you can use high-priority mobile data at the same time as WiFi. The value of the "feature" parameter is "enableHIPRI", and is hidden in the Phone API.

Method: ConnectivityManager.startUsingNetworkFeature(int networkType, String feature) of http://developer.android.com/reference/android/net/ConnectivityManager.html

Source: http://code.google.com/p/android/issues/detail?id=5885

You could check this other answer: https://stackoverflow.com/a/4756630/327011

This is NOT a good policy...use it if REALLY needed!

like image 34
neteinstein Avatar answered Oct 20 '22 10:10

neteinstein


ConnectivityManager.setNetworkPreference() is close to be obsoleted. But what is more important, if you do getNetworkPreference() before changing, it will return ConnectivityManager.TYPE_MOBILE. Setting it there does not make any difference. As for HIPRI itself, it works in pretty strange mode. First, it allows connections to all hosts, not only to those explicitly requested. Second, when you turn it off with stopUsingFeature...() call, it will not be turned off and will be still active. Third, all device applications start using it even if wifi is available, which contradicts to what is said in documentation.

like image 1
Cynichniy Bandera Avatar answered Oct 20 '22 11:10

Cynichniy Bandera