Reputation: 2881
in my application i need to find the speed of connected network (wifi/GPRS/3G). Here i need help to find the speed of GPRS/3G network. Can you please help me how to solve this problem.
Upvotes: 4
Views: 5410
Reputation: 510
maybe it is possible to figure out, that user is connected to wifi, gprs, or g3 network. Then you can figure out how fast is each technology. Also you can put file (for example 3MB) on fast connection server. Then you can download that file and measure time, how long it takes. Then just calculate... Or You can calculate it after each second while file is downloading.
Also download speed may vary from various conditions. Like network strength (booth wireless and mobile). For example, if user is connected to 54mbit wifi and access point is 60 meters form user, then download speed wont be even half of that. Here is example with download speed calculations java howto calculate Mbit/s during while loop download
Upvotes: 0
Reputation: 3870
TrafficStats will do the work. You can get bytes transferred, then you can calculate the speed.
Upvotes: 1
Reputation: 30210
This isn't a complete answer either, but for Wifi networks (not cellular), you can get the link rate through something like the following:
public String getLinkRate()
{
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo wi = wm.getConnectionInfo();
return String.format("%d Mbps", wi.getLinkSpeed());
}
A few things to note:
android.permission.ACCESS_WIFI_STATE
permission.Upvotes: 1
Reputation: 30944
Have a look at Zwitscher's NetworkHelper class
Basically you need to obtain the ConnectivityManager
cManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
and then query this for what you want to know
NetworkInfo info = cManager.getActiveNetworkInfo();
int type = info.getType();
int subType = info.getSubtype();
For more info, browse the above class to see the meanings of type
and subType
.
Upvotes: -1