Android: How to determine Network speed in android programmatically

前端 未结 8 1072

How to show a slow internet connection to the user when the network is connected Note: Not a network type (2G,3G,4G, WIFI)

8条回答
  •  天命终不由人
    2020-12-31 09:25

    UPDATE - DEPRECATED LIBRARY - no longer mainteined

    original post:

    You can use Network Connection Class by Facebook.

    Its ConnectionClassStateChangeListener has a method called onBandwidthStateChange that returns an instance of ConnectionQuality class:

    public interface ConnectionClassStateChangeListener {
      public void onBandwidthStateChange(ConnectionQuality bandwidthState);
    }
    

    ConnectionQuality class is an enum class defined as below:

    public enum ConnectionQuality {
      /**
       * Bandwidth under 150 kbps.
       */
      POOR,
      /**
       * Bandwidth between 150 and 550 kbps.
       */
      MODERATE,
      /**
       * Bandwidth between 550 and 2000 kbps.
       */
      GOOD,
      /**
       * EXCELLENT - Bandwidth over 2000 kbps.
       */
      EXCELLENT,
      /**
       * Placeholder for unknown bandwidth. This is the initial value and will stay at this value
       * if a bandwidth cannot be accurately found.
       */
      UNKNOWN
    }
    

提交回复
热议问题