Android:如何以编程方式确定Android中的网络速度 [英] Android: How to determine Network speed in android programmatically
问题描述
如何在网络连接后向用户显示缓慢的Internet连接注意:不是网络类型(2G,3G,4G,WIFI)
How to show a slow internet connection to the user when the network is connected Note: Not a network type (2G,3G,4G, WIFI)
推荐答案
确定网络速度-(Internet速度慢)
Determining your Network Speed - (Slow Internet Speed)
使用NetworkInfo类,ConnectivityManager和TelephonyManager确定您的网络类型.
Using NetworkInfo class, ConnectivityManager and TelephonyManager to determine your Network Type.
从互联网上下载任何文件&计算花费了多长时间与文件中的字节数.(确定速度检查的唯一可能方法)
Download any file from the internet & calculate how long it took vs number of bytes in the file. ( Only possible way to determine Speed Check )
我已经为我的项目尝试了以下逻辑,您也对此进行了研究,希望它对您有帮助.
I have tried the below Logic for my projects, You have also look into this, Hope it helps you.
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
//should check null because in airplane mode it will be null
NetworkCapabilities nc = cm.getNetworkCapabilities(cm.getActiveNetwork());
int downSpeed = nc.getLinkDownstreamBandwidthKbps();
int upSpeed = nc.getLinkUpstreamBandwidthKbps();
这篇关于Android:如何以编程方式确定Android中的网络速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!