Android中的慢速互联网连接问题 [英] Slow internet connection issue in android

查看:102
本文介绍了Android中的慢速互联网连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Android中创建一个应用程序,用于检查Internet连接。我想在互联网连接速度很慢时显示一条祝酒消息。或服务器不响应请求时。在这种情况下,我想像连接速度慢!那样敬酒。在我的代码中,我发现了是否已连接互联网,但不知道如何慢速发送互联网消息...

I'm creating an application in Android in which checks the Internet connectivity. I want to display a toast message when the Internet connection is very slow. Or when the server does not respond to a request. In this case I want to put a toast like Connection is slow !!!. Here in my code I have found the whether the internet is connected or not, but don't know how to toast the message of internet slow...

public boolean isConnectingToInternet(){
    ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
      if (connectivity != null) 
      {
          NetworkInfo[] info = connectivity.getAllNetworkInfo();
          if (info != null) 
              for (int i = 0; i < info.length; i++) 
                  if (info[i].getState() == NetworkInfo.State.CONNECTED)
                  {
                      return true;
                  }

      }
      return false;
}


推荐答案


  • 对于WiFi链接速度,请检查 WifiInfo.getLinkSpeed()

  • 对于移动数据链接,您只能检查 TelefonyManager.getNetworkType()确定当前的移动数据链接类型。然后,您应该根据链路类型(例如GPRS最高128 kbps,EDGE最高236.8 kpbs,3G最高2 Mbps,HDSPA最高7.2 Mbps)接近实际速度。考虑到这仅仅是一个近似。您可以使用HDSPA进行联网,但是运营商将最高速度限制为2 Mbps。

    • For WiFi link speed check WifiInfo.getLinkSpeed()
    • For Mobile Data Link you can only check TelefonyManager.getNetworkType() to determine the current Mobile Data Link type. You should then aproximate to actual speed by link type (i.e. for GPRS up to 128 kbps, for EDGE up to 236.8 kpbs, for 3G up to 2 Mbps, for HDSPA up to 7.2 Mbps). Take into consideration that this is only an aproximation. Your could be conneting using HDSPA but your carrier limiting the top speed to 2 Mbps.
    • 现在,您必须获得速度并满足条件是否低于100kbps,互联网连接速度低

      Now , you have to get speed and put condition whether below 100kbps , "low internet connection"

      这篇关于Android中的慢速互联网连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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