简体   繁体   English

棒棒糖WiFi连接不良并回退到移动网络,如何检测?

[英]Lollipop Bad WiFi connection and Fallback to Mobile Network, how to Detect?

Lollipop has a new feature which is causing a huge problem for me. 棒棒糖具有一项新功能,这对我造成了巨大的问题。 The system will fall back, transparently, to Mobile data when the WiFi network is "connected" but has no internet. 当WiFi网络“连接”但没有互联网时,系统将透明地退回到移动数据。 http://www.androidpolice.com/2014/10/18/lollipop-feature-spotlight-android-now-defaults-to-mobile-data-when-wi-fi-has-no-internet-access-signal-icon-adds-a-for-no-connection/ http://www.androidpolice.com/2014/10/18/lollipop-feature-spotlight-android-now-defaults-to-mobile-data-when-wi-fi-has-no-internet-access-signal-图标增加,一个换无连接/

Since one of the apps I make for my company is a WiFi testing application, similar to Fing etc, this is causing issues in Lollipop. 由于我为公司制作的应用程序之一是WiFi测试应用程序,类似于Fing等,因此导致Lollipop出现问题。 I NEED to send packets out on the bad WiFi signal, so that problems can be located and fixed, ex Traceroute, Ping etc. While external IP's may not work, internal IP addresses should still be reachable in a scenario like this. 我需要通过错误的WiFi信号发送数据包,以便可以定位和解决问题,例如Traceroute,Ping等。虽然外部IP可能无法正常工作,但在这种情况下内部IP地址仍然应该可以访问。 However with the connection automatically falling back to the mobile network this is not longer possible. 但是,随着连接自动回退到移动网络,这将不再可能。

I have not yet found any solution to detecting this. 我尚未找到检测此问题的任何解决方案。 NetworkInfo.getState() and NetworkInfo.getDetailedState() both report "DISCONNECTED" even though the WiFi is connected and just has a bad external connection. 即使WiFi已连接并且外部连接不良, NetworkInfo.getState()NetworkInfo.getDetailedState()均报告为“ DISCONNECTED”。 Does anyone have any suggestions? 有没有人有什么建议? All research thus far has led me to believe I can't force packets over the WiFi connection in Android, and I haven't figured out if I can detect this state. 到目前为止,所有的研究都使我相信我无法在Android中通过WiFi连接强制发送数据包,而且我还不确定是否可以检测到这种状态。 Other than detecting if Mobile data is on, and asking the user to turn it off, what are my options? 除了检测移动数据是否打开并要求用户关闭移动数据外,我还有哪些选择?

You can request a specific connection type (or a specific network) using ConnectivityManager#requestNetwork() . 您可以使用ConnectivityManager#requestNetwork()请求特定的连接类型(或特定的网络ConnectivityManager#requestNetwork()

You can then use a NetworkRequest.Builder to request a WiFi network like so: 然后,您可以使用NetworkRequest.Builder来请求WiFi网络,如下所示:

ConnectivityManager cm = 
        (ConnectivityManager) Context.getSystemService(Context.CONNECTIVITY_SERVICE);

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

cm.requestNetwork(request,
                  new ConnectivityManager.NetworkCallback() {
                      void onAvailable(Network network) {
                         // Do something once the network is available
                      }
                  });

The builder also allows you to specify additonal constraints (called "capabilities"), so you can optionally speficy more requirements such as a specific SSID. 该构建器还允许您指定附加约束(称为“功能”),因此您可以有选择地指定更多要求,例如特定的SSID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 确定网络连接带宽(速度)wifi和移动数据 - Determine Network Connection Bandwidth (speed) wifi and mobile data 如何检测用户何时将一个wifi连接转到另一个wifi? - How to detect when user turn one wifi connection to other wifi? 在Midp中检测wifi和网络连接 - Detect wifi and network connectivity in midp 如何从 Android 应用程序检测 WiFi 网络中连接的所有设备 - How to detect all the Devices connected in a WiFi network from Android App 如何选择/强制使用移动数据(或wifi)在Android上进行网络通话? - How to choose/enforce using mobile data (or wifi) for network calls on Android? 如何在Android中检测用户何时连接到wifi或移动互联网 - How to detect when user connects to wifi or mobile internet in android Android - 如何检测慢速网络连接? - Android - How to detect slow network connection? 如何检查互联网连接(Wifi /移动数据)是否已启用? - How to check if the Internet connection (Wifi/Mobile data) is ENABLED? 如何处理网络状态变化的在线媒体播放器(WiFi 或移动数据之间的网络转换)? - How to handle online media player on network state change (network shifts between WiFi or mobile data)? 局域网中的Wifi游戏检测服务器 - Wifi Game Detect Servers in Local Area Network
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM