Network Connection Class

Android Network Connection Class Library

License

License

Categories

Categories

Net
GroupId

GroupId

com.facebook.network.connectionclass
ArtifactId

ArtifactId

connectionclass
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Network Connection Class
Android Network Connection Class Library
Project URL

Project URL

https://github.com/facebook/network-connection-class
Source Code Management

Source Code Management

https://github.com/facebook/network-connection-class.git

Download connectionclass

How to add to project

<!-- https://jarcasting.com/artifacts/com.facebook.network.connectionclass/connectionclass/ -->
<dependency>
    <groupId>com.facebook.network.connectionclass</groupId>
    <artifactId>connectionclass</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.facebook.network.connectionclass/connectionclass/
implementation 'com.facebook.network.connectionclass:connectionclass:1.0.1'
// https://jarcasting.com/artifacts/com.facebook.network.connectionclass/connectionclass/
implementation ("com.facebook.network.connectionclass:connectionclass:1.0.1")
'com.facebook.network.connectionclass:connectionclass:jar:1.0.1'
<dependency org="com.facebook.network.connectionclass" name="connectionclass" rev="1.0.1">
  <artifact name="connectionclass" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.facebook.network.connectionclass', module='connectionclass', version='1.0.1')
)
libraryDependencies += "com.facebook.network.connectionclass" % "connectionclass" % "1.0.1"
[com.facebook.network.connectionclass/connectionclass "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
com.google.code.findbugs : jsr305 jar 2.0.1

Project Modules

There are no modules declared in this project.

Network Connection Class Network Connection Class

Network Connection Class is an Android library that allows you to figure out the quality of the current user's internet connection. The connection gets classified into several "Connection Classes" that make it easy to develop against. The library does this by listening to the existing internet traffic done by your app and notifying you when the user's connection quality changes. Developers can then use this Connection Class information and adjust the application's behaviour (request lower quality images or video, throttle type-ahead, etc).

Network Connection Class currently only measures the user's downstream bandwidth. Latency is also an important factor, but in our tests, we've found that bandwidth is a good proxy for both.

The Network Connection Class library takes care of spikes using a moving average of the incoming samples, and also applies some hysteresis (both with a minimum number of samples and amount the average has to cross a boundary before triggering a bucket change): Bandwidth Averaging

Integration

Download

Download the latest JARs or grab via Gradle:

compile 'com.facebook.network.connectionclass:connectionclass:1.0.1'

or Maven:

<dependency>
  <groupId>com.facebook.network.connectionclass</groupId>
  <artifactId>connectionclass</artifactId>
  <version>1.0.1</version>
</dependency>

Calculate Connection Class

Connection Class provides an interface for classes to add themselves as listeners for when the network's connection quality changes. In the subscriber class, implement ConnectionClassStateChangeListener:

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

and subscribe with the listener:

ConnectionClassManager.getInstance().register(mListener);

Alternatively, you can manually query for the current connection quality bucket with getCurrentBandwidthQuality().

ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();

The main way to provide the ConnectionClassManager data is to use the DeviceBandwidthSampler. The DeviceBandwidthSampler samples the device's underlying network stats when you tell it you're performing some sort of network activity (downloading photos, playing a video, etc).

// Override ConnectionClassStateChangeListener
ConnectionClassManager.getInstance().register(mListener);
DeviceBandwidthSampler.getInstance().startSampling();
// Do some downloading tasks
DeviceBandwidthSampler.getInstance().stopSampling();

If the application is aware of the bandwidth downloaded in a certain time frame, data can be added to the moving average using:

ConnectionClassManager.addBandwidth(bandwidth, time);

See the connectionclass-sample project for more details.

Improve Connection Class!

See the CONTRIBUTING.md file for how to help out.

License

Connection Class is BSD-licensed. We also provide an additional patent grant.

com.facebook.network.connectionclass

Facebook

We are working to build community through open source technology. NB: members must have two-factor auth.

Versions

Version
1.0.1
1.0.0