PeterJ
PeterJ

Reputation: 3795

Android force traffic over internet while WiFi enabled

I'm starting to write an Android application to perform background monitoring of my web server. With WiFi enabled a problem will be that traffic is directed over that by default, I'd like to always use 3G for the HTTP request to check external availability as well. I know I could use this code to disable WiFi programmatically:

WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);

But as it will be running in the background it's a bit clumsy and will interrupt other operations over WiFi while the check is in progress. Looking at the Socket Documentation I can't see any apparent way to achieve this. I'm wondering if there's any supported way to achieve this on a non-rooted phone? I have full control over the server so the protocol doesn't specifically have to be HTTP.

Upvotes: 4

Views: 11422

Answers (2)

Sahil Mahajan Mj
Sahil Mahajan Mj

Reputation: 11141

This seems like it would be an awfully dangerous feature for Android to allow.

  • What about users who are on metered 3G plans? How would they feel if an app forced them to use a 3G connection and then bugged out or something and blew away their whole data quota without them even knowing it (thinking they were on WiFi)?

  • Also, there could not be more than one active networks at a time.

Possible Resolutions-

  • What you can do is to force disable the wifi network, when your application is active and then enable it later.

  • Also, Try searching for a method called requestRouteToHost. It allows you to specify the network type and the host you want to find a route to.

Upvotes: 1

Anup Cowkur
Anup Cowkur

Reputation: 20563

I don't believe you can do this in android since only one network connection is active at any given time. A similar question is posted here as well:

Send HTTP request through 3G network without using WiFi?

Upvotes: 1

Related Questions