I am developing a mobile application (iOS and Android) to control a device over Wi-Fi. The device creates a wireless network (SoftAP) but does not provide access to the internet.
On iOS, I can connect to the device and make requests to its IP address (192.168.70.1) but all other requests fall back to the mobile network. This allows the phone to maintain internet connectivity while connected to the device over Wi-Fi.
On Android, if I connect to the device wireless network, internet requests do not fall back to the mobile connection, they just fail.
In my Android app, I can use ConnectivityManager.requestRouteToHost
to force requests from my app to use the mobile network. However, requests made by other apps still use the device wifi network and fail.
I have also tried to use the ConnectivityManager
to change the network preference with :
ConnectivityManager.setNetworkPreference(ConnectivityManager.TYPE_MOBILE)
This causes the phone to use the mobile network for all requests from all applications. Wi-Fi is disabled. It seems that in previous versions of Android Wi-Fi could still be used even if it is not the "preferred" network but this does not seem to work in KitKat. It is possibly related to a change in Android 4.2: https://code.google.com/p/android/issues/detail?id=73509 "ConnectivityManager since 4.2 tears down networks that are not the NetworkPreference"
Is there a solution that allows an Android app to use Wi-Fi for a specific IP address and the mobile network for everything else? Maybe this can be done via the NDK?