我正在使用包含web服務的應用程序。在android中計算互聯網速度
因爲我需要知道互聯網速度低時的狀態。如何在Android中查找互聯網速度級別?
例如,考慮如果我在手機中使用2Mbps連接,並且速度降至50Kbps,我需要通過發出Toast或Alert來注意這種情況。
謝謝。
我正在使用包含web服務的應用程序。在android中計算互聯網速度
因爲我需要知道互聯網速度低時的狀態。如何在Android中查找互聯網速度級別?
例如,考慮如果我在手機中使用2Mbps連接,並且速度降至50Kbps,我需要通過發出Toast或Alert來注意這種情況。
謝謝。
如果您連接到WiFi
您可以使用WifiManager
找到的連接速度:
WifiInfo wifiInfo = wifiManger.getConnectionInfo();
,然後從WifiInfo
就可以得到當前的速度:
int speedMbps = wifiInfo.getLinkSpeed();
如果你是在3G上,我不認爲有一個標準的發現方式,也許你可以自動假設3G是慢的。
任何方式謝謝你,但我仍然在尋找互聯網速度不僅在無線以及在3G,2G。 – Dhamodharan 2012-08-03 13:42:26
這個答案是不正確的,這是不可能的,因爲它取決於你的ISP,而不是你的WiFi適配器或路由器 – mittelmania 2014-12-27 08:56:00
沒有提供網絡速度的android庫。 'wifiInfo.getLinkSpeed'提供了不斷更新的網絡的最大速度。 – 2016-07-04 12:25:11
這是specilally通過 facebook sdk
ConnectionQuality cq = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
檢測的互聯網連接速度。這是讓你的互聯網的速度,同時Wi-Fi連接的代碼。
WifiManager wifiManager = (WifiManager)
this.getSystemService(Context.WIFI_SERVICE);
List<ScanResult> wifiList = wifiManager.getScanResults();
for (ScanResult scanResult : wifiList) {
int level = WifiManager.calculateSignalLevel(scanResult.level, 5);
String net=String.valueOf(level);
// Toast.makeText(MainActivity.this,net,Toast.LENGTH_LONG).show();
}
// Level of current connection.here rssi is the value of internet speed whose value
// can be -50,-60 and some others,you can find the speed values easily on internet.
int rssi = wifiManager.getConnectionInfo().getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 5);
String net=String.valueOf(rssi);
Toast.makeText(MainActivity.this,net,Toast.LENGTH_LONG).show();
// -100 is the minimum speed value of your internet.
if(rssi < -100) {
slowInternet=false;
}
這可能有助於http://stackoverflow.com/questions/4429605/how-to-get-link-speed-programmatically – Calvin 2012-09-20 07:57:40