检测有限的网络连通性的Andr​​oid? [英] Detecting limited network connectivity in Android?

查看:191
本文介绍了检测有限的网络连通性的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些关于如何检测的网络连接在机器人的问题。 http://stackoverflow.com/a/4239019/90236 提供了一个非常详细的解答和的http://stackoverflow.com/a/8548926/90236 的显示方法来识别网络的哪一个被连接的类型。

我们使用code相似的答案像检测网络连接:

 私人布尔isNetworkAvailable(){
    ConnectivityManager connectivityManager
          =(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    的NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    返回activeNetworkInfo = NULL和放大器;!&安培; activeNetworkInfo.isConnected();
}
 

这让我们提醒用户,如果他们处于脱机状态。但是,它并不能帮助我们确定用户是否有限的连接。有有限的连通性已经引起用户抱怨的条件。这些措施包括:

  1. 用户被连接到家庭网络的WiFi但电缆调制解调器或因特网服务不可用。

  2. 用户是在一个酒店或咖啡馆,并成功地连接到WiFi网络,但网络要求他们登录或同意服务条款,给予他们充分的网络访问之前。

在这两种情况下我们isNetworkAvailable()测试返回true。操作系统告诉我们都连接到一个网络。但是,用户不具有可用的互联网连接。

有没有好的方法来确定用户具有一个全功能的网络连接?

我在考虑调用一个轻量级的Web服务,以验证它们的连接,并警告用户,如果应用程序没有得到来自服务的有效回报。这是矫枉过正?或者有其他国家不得不采取类似的技术?

解决方案
  

有没有好的方法来确定用户具有一个全功能的网络连接?

尝试下载一些东西的地方。理想情况下,地方是你自己的服务器,为设备和服务器之间的测试连接。

唉,没有 doesTehConnexionSuck() iCanHazBandwidth()的方法 ConnectivityManager 。 : - )

  

这是大材小用?

在的金发姑娘和三只熊的精神,我会形容为justrightkill。

我们要做的有心计的Web应用程序也。

There are a number of questions regarding how to detect network connectivity in Android. http://stackoverflow.com/a/4239019/90236 provides a very detailed answer and http://stackoverflow.com/a/8548926/90236 shows methods to identify the type of network to which one is connected.

We detect network connectivity using code similar to those answers like:

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager 
          = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

This lets us warn a user if they are offline. However, it doesn't help us identify if a user has limited connectivity. There are conditions of limited connectivity that have caused users to complain. These include:

  1. Users are connected to a home wifi network but the cable modem or Internet service is unavailable.

  2. Users are in a hotel or coffee shop and successfully connect to a wifi network, but the network requires that they login or agree to terms of service before they are given full network access.

In both of these situations our isNetworkAvailable() test returns true. The OS tells us we are connected to a network. However, the user does not have usable Internet connectivity.

Is there a good way to determine that the user has a fully functioning network connection?

I'm considering calling a lightweight web service to verify their connectivity and warn the user if the app doesn't get a valid return from the service. Is this overkill? or have others had to resort to similar techniques?

解决方案

Is there a good way to determine that the user has a fully functioning network connection?

Try downloading something from somewhere. Ideally, the "somewhere" is your own server, to test connectivity between the device and your server.

Alas, there are no doesTehConnexionSuck() or iCanHazBandwidth() methods on ConnectivityManager. :-)

Is this overkill?

In the spirit of "Goldilocks and the Three Bears", I'd describe that as justrightkill.

We have to do the same sorts of shenanigans in Web apps too.

这篇关于检测有限的网络连通性的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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