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
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."
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.
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.
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!
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With