当Wi-Fi无法访问互联网时,Android Lollipop默认使用移动数据网络? [英] Android Lollipop defaults to Mobile Data when Wi-Fi has not Internet access?

查看:400
本文介绍了当Wi-Fi无法访问互联网时,Android Lollipop默认使用移动数据网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您连接到 Wi-Fi 时,Android Lollipop 似乎默认使用移动数据。有人知道这是否在正式记录在某处?

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?

我们有一个应用程序需要通过 Wi-Fi连接到机器没有互联网。我们的客户现在报告 Wi-Fi 连接不再工作,因为手机会自动切换到 LTE

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.

我的理解是,手机仍然保持 Wi-Fi 连接,但使用 LTE ,除了提供对互联网的访问( lollipop-feature-spotlight-android-now-defaults- mobile-data-when-wi-fi-has-no-internet-access-signal-icon-adds-a-for-no-connection )。

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).

我对这个功能的理解错了吗?如果是,有没有办法强制使用无互联网的Wi-Fi?

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.

任何帮助都非常感激。

推荐答案

要扩展@ ianhanniballake的答案,我发现使用 ConnectivityManager.setProcessDefaultNetwork()阻止漫游,并允许完全TCP访问。因此,在 onAvailable()回调中,您可以将应用进程绑定到该网络,而不是打开到特定URL的连接。

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);
    }
}

这篇关于当Wi-Fi无法访问互联网时,Android Lollipop默认使用移动数据网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆