Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lollipop defaults to Mobile Data when Wi-Fi has not Internet access?

Android Lollipop seems to default to Mobile Data when the Wi-Fi you are connected to has no Internet access. Does anybody know if this is officially documented somewhere?

We have an application that needs to connect to machines via Wi-Fi that do not have Internet. Our customers are now reporting that the Wi-Fi connection does not work anymore, because the phone automatically switches to LTE.

My understanding would be that the phone still keeps the Wi-Fi connection but uses LTE in addition to provide access to the Internet (lollipop-feature-spotlight-android-now-defaults-to-mobile-data-when-wi-fi-has-no-internet-access-signal-icon-adds-a-for-no-connection).

Is my understanding of this feature wrong? And if so, is there a way to force using the Wi-Fi without Internet? I could not find anything about this in particular in the developer documentation.

Any help is really appreciated.

like image 613
Florian Avatar asked Nov 27 '14 06:11

Florian


People also ask

Why is my Android phone using data when connected to WiFi?

If your phone detects that the Wi-Fi network stutters, it will switch to the mobile network, so that your phone still consumes mobile data even if it is connected to the Wi-Fi network. To disable Wi-Fi+, go to Settings, search for and access Wi-Fi+, and disable it.

How do I prioritize my mobile data over WiFi on Android?

Prioritize Android Wi-Fi Network Using Built-In Settings To check if your ROM has one, open Settings > Network & internet > Wi-Fi. Tap on the overflow menu, then hit Advanced Wi-Fi. If you see a Wi-Fi Priority option, you can specify the priority of Wi-Fi networks here.

Why does my WiFi have no Internet access on my phone?

Restart your device. If restarting doesn't work, switch between Wi-Fi and mobile data: Open your Settings app and tap Network & internet or Connections. Depending on your device, these options may be different. Turn Wi-Fi off and mobile data on, and check if there's a difference.

Why is my phone always connected without internet?

A common reason why your phone has a WiFi connection but no Internet access is that there is a technical issue with your router. If your router is experiencing any kind of bugs or problems, that affects how your Android devices stay connected to WiFi.


3 Answers

To extend on @ianhanniballake's answer, I've found that binding the network using ConnectivityManager.setProcessDefaultNetwork() prevents roaming and allows for full TCP access. Thus, within the onAvailable() callback you could bind the application process to that network rather than opening a connection to a particular URL.

ConnectivityManager connection_manager = 
    (ConnectivityManager) activity.getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkRequest.Builder request = new NetworkRequest.Builder();
request.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);

connection_manager.registerNetworkCallback(request.build(), new NetworkCallback() {

    @Override
    public void onAvailable(Network network) {
        ConnectivityManager.setProcessDefaultNetwork(network);
    }
}

As of API Level 23: Please use the following OnAvailable Method:

@Override
public void onAvailable(Network network) {
    connection_manager.bindProcessToNetwork(network);
}
like image 192
Tez Avatar answered Nov 15 '22 17:11

Tez


By default, Android 5.0 will only send network requests over networks that it detect have an active internet connection so while it may be 'connected' to the wifi, it is not going to send any data over the network.

However, the Android 5.0 APIs guide talks about the new multiple network support:

Android 5.0 provides new multi-networking APIs that let your app dynamically scan for available networks with specific capabilities, and establish a connection to them. This functionality is useful when your app requires a specialized network, such as an SUPL, MMS, or carrier-billing network, or if you want to send data using a particular type of transport protocol.

This allows you to build a NetworkRequest for a TRANSPORT_WIFI type and direct traffic to it via Network.openConnection() when you receive a onAvailable() callback if you must have certain connections happen over wifi even when the wifi network does not have internet access.

like image 29
ianhanniballake Avatar answered Nov 15 '22 18:11

ianhanniballake


Android 5.0 provides new multi-networking APIs that let your app dynamically scan for available networks with specific capabilities, and establish a connection to them. More info here

So solution for you is ConnectivityManager.requestNetwor().

like image 24
Petr Duchek Avatar answered Nov 15 '22 18:11

Petr Duchek