Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to select which network interface to use?

Tags:

android

I have an app which is used to connect to a service running on the user's home PC.

There are two 'simple' scenarios...

  1. The user has wi-fi enabled on their device and simply connects using their home WLAN.
  2. The user is away from a wi-fi connection and they are able to connect with mobile internet

I'm now faced with a more complex scenario which is when the user is at their place of work and their device detects/connects to their office WLAN and there is no route to the outside world.

The problem is that even if they have both wi-fi AND mobile internet enabled on their device, the wi-fi interface will normally be used in preference to the mobile internet interface when any app attempts to connect to the internet.

So the question is, can I somehow bind to the mobile interface and make an outgoing connection even when the wi-fi interface is taking priority? If so, any pointers to information on how to achieve this would be useful. Thanks.

like image 562
Squonk Avatar asked Nov 05 '22 01:11

Squonk


1 Answers

This is where I would start digging. ConnectivityManager.requestRouteToHost

The primary responsibilities of this class are to:

Monitor network connections (Wi-Fi,GPRS, UMTS, etc.)

Send broadcast intents when network connectivity changes

Attempt to "fail over" to another network when connectivity to a network is lost

Provide an API that allows applications to query the coarse-grained or fine-grained state of the available networks

I'd also try grep'ing over the AOSP code to see where and how it is used.

like image 71
smith324 Avatar answered Nov 14 '22 22:11

smith324