Paul Sen
Paul Sen

Reputation: 554

Getting upload and Download bandwidth in Android using NetworkCapabilities class

I am working on a small video streaming application.I want to get the upload and download speed of network in Android.i discovered that we can do that by using Android NetworkCapabilities class which provides functions

getLinkDownstreamBandwidthKbps()
Retrieves the downstream bandwidth for this network in Kbps. 
This always only refers to the estimated first hop transport bandwidth.

getLinkUpstreamBandwidthKbps ()
Retrieves the upstream bandwidth for this network in Kbps. 
This always only refers to the estimated first hop transport bandwidth.

1.What does first hop Here Mean ?

2.How to use them.Please provide some link for reference that how can we use them ?

Upvotes: 3

Views: 3988

Answers (1)

Mimmo Grottoli
Mimmo Grottoli

Reputation: 5773

Provided that you're in an Activity you can get the info in this way:

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network[] networks = cm.getAllNetworks();
...cycle or choose a network...
NetworkCapabilities capabilities = cm.getNetworkCapabilities(network);

The first hop means that it is an estimate of the capabilities of your link not an estimate of the bandwidth you'll get when your traffic will be routed over the network to reach your endpoint. Please note that this methods are availble from Lollipop.

Upvotes: 5

Related Questions