10

I have an Android app and a server available through Wi-Fi.
For some operations (e.g. video streaming from the server) my app uses third-party apps by sharing the URL of the file.

Starting from Android L device can be connected to both Wi-Fi and cellular simultaneously, which breaks my app since the server doesn't have Internet and cellular network is getting preferred by Android (since it has Internet), so URL cannot be resolved. I fixed this by binding my app to Wi-Fi with bindProcessToNetwork(). But when the app shares the URL with 3'rd-party app, the URL still cannot be resolved since 3'rd-party app is not bind to Wi-Fi.

Is there a way to let 3'rd party app use Wi-Fi instead of cellular while opening the URL my app provided?

enter image description here

Carlos
  • 5,991
  • 6
  • 43
  • 82
surlac
  • 2,961
  • 2
  • 22
  • 31
  • though i don't have real code to achieve this, or if it's even possible, but i would search for manipulating the `Routing Table` in this case, to set requests using server's IP to use Wifi as gateway, and other requests to use 3G, this -theorically- will be OS level effect, so all apps will follow, second option i think you could turn off cell-data when your app is started,i know this could be dirty, an Alert message can be good to inform the user about this action – Yazan Feb 15 '16 at 09:03

2 Answers2

0

Here you have an explanation on how to force a type of network to a specific address:

How to use 3G Connection in Android Application instead of Wi-fi?

If you know the URL of the 3rd party services you can try it. Remember that the code relies on network so it should run off the UI thread. Also this code uses some deprecated methods.

Community
  • 1
  • 1
Felipe Duarte
  • 1,079
  • 14
  • 20
  • I don't think it really solves the problem: **1.** the proposed solution forces cellular instead of Wi-Fi; **2.** it uses deprecated apis (e.g. requestRouteToHost()); **3.** it forces _Your_ app to use specific network for a specific host, but we're talking about 3'rd party apps. – surlac Feb 08 '16 at 19:56
  • @surlac: 1. Yes, you should change the code to http://developer.android.com/reference/android/net/ConnectivityManager.html#TYPE_WIFI .. 2. I forgot to mention it on my answer, will update. 3. As I said, if you know what servers your 3rd party uses, you can try to force that host. Anyway, I was just throwing some ideas instead of answering: "No, you can't" ;) – Felipe Duarte Feb 08 '16 at 20:18
  • I think I understand your problem and I believe, yes, you can do what you want to do. Assign the private IP address of your internal server to a public domain name. For example I own a domain name (let's call it elvis.com). On my public DNS with my ISP, I created b.elvis.com and it points to 192.168.1.6 which sits inside my private network. Does this help? –  Feb 15 '16 at 16:04
0

There are many many ways to achieve that ... first off the top of my head is create a a vpn app that captures all traffic flowing into and out of the device and re-rout as appropriate, so even if your 3rd party app thinks its using cellular its actual tcp packets can be coming from somewhere completely different, even bluetooth if you want to.

Second, quick and dirty (not sure, havent tried that but a quick google search threw that my way) , go to your data usage, enable data cutoffs (the red and orange lines) doesnt matter what you set them to but they have to be enabled. Next scroll down you will find a list of apps using data, find your 3rd party app, you'll find another checkbox to limit its background data,mark it. Now this 3rd party app can no longer use mobile data without your consent: only actions you triggered yourself ("foreground data") will be performed by it, no sync in the background or other background activity. So if YOUR app shares the URL internally with the 3rd Party app and no ui is involved, then that should work

if you just copy and paste the URL manually, then while your at it manually turn of mobile data.

a.atlam
  • 742
  • 5
  • 17