【问题标题】:Android : How to get internet connection upload speed and latency?Android:如何获得互联网连接上传速度和延迟?
【发布时间】:2012-06-16 08:34:20
【问题描述】:

我想查找设备网络上传速度和延迟,我尝试了 FTP 文件上传但没有成功。有人可以帮我确定网络上传速度吗?

【问题讨论】:

    标签: android file-upload network-programming


    【解决方案1】:

    获取当前网络连接类型:

    TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    int networkType = telephonyManager.getNetworkType();
    


    以及延迟:

    String host = "172.16.0.2";
    int timeOut = 3000; 
    long[] time = new long[5];
    Boolean reachable;
    
    for(int i = 0; i < 5; i++)
    {
      long BeforeTime = System.currentTimeMillis();
      reachable = InetAddress.getByName(host).isReachable(timeOut);
      long AfterTime = System.currentTimeMillis();
      Long TimeDifference = AfterTime - BeforeTime;
      time[i] = TimeDifference;
    }
    

    【讨论】:

      【解决方案2】:

      我关注this link 并获得了几乎正确的下载速度。为了提高上传速度,我创建了一个 PHP api,将其上传到 FTP 服务器并从设备调用它并上传一个文件。然后我计算上传前和上传后的时间得到上传速度。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-10-14
        • 1970-01-01
        • 2011-09-08
        • 2018-02-09
        • 2021-02-17
        • 1970-01-01
        相关资源
        最近更新 更多