开发者

How to find the GPRS/3G network data transfer speed in android?

in my application i need to find the speed 开发者_StackOverflowof 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.


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:

  1. This will require the android.permission.ACCESS_WIFI_STATE permission.
  2. It will always be one of the rates specified by the 802.11 standard (see the table here)
  3. It is only the rate that the handset and AP have negotiated as the maximum rate. A lot of factors come into play that affect the actual rate you'd get while, say surfing the web (e.g. wireless congestion and collisions, the upstream link rate)


TrafficStats will do the work. You can get bytes transferred, then you can calculate the speed.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜