stefan
stefan

Reputation: 1376

Android ad hoc wifi connection but keep internet connection

My application creates a Wi-Fi connection to a sensor but this means that the user will have no connection to the Internet as long as he is connected to this peripheral.

I've already read that it is not possible to have two wifi connection without rooting the device.

I guess I've already read all posts on stack overflow concerning this topic but all of them are quite old.

It would be ok if I could use at least the mobile network for Internet so that the user is able to use the browser or other applications while connected.

I tried to set the preferred network but this is not working.

  try {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        if (forceMobile) {
            connectivityManager.setNetworkPreference(ConnectivityManager.TYPE_MOBILE);
        } else {
            connectivityManager.setNetworkPreference(ConnectivityManager.DEFAULT_NETWORK_PREFERENCE);
        }
    } catch (Exception exc) {

    }

Upvotes: 0

Views: 488

Answers (1)

Sahil Bahl
Sahil Bahl

Reputation: 591

If connected to another sensor over wifi . You still wont be able to connect to internet through mobile data as at a time only one of the two interfaces can be connected in most of devices(There might be some exceptions). The best way to achieve this if you could connect to the sensor using bluetooth and stay connected to internet over wifi or mobile data .Since bluetooth and mobile data or Wifi can stay connected in parallel.

Upvotes: 1

Related Questions