要获取当前网络连接类型:
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
int networkType = telephonyManager.getNetworkType();
并为延迟:
String host = "172.16.0.2";
int timeOut = 3000;
long[] time = new long[5];
Boolean reachable;
for(int i = 0; i < 5; i++)
{
long BeforeTime = System.currentTimeMillis();
reachable = InetAddress.getByName(host).isReachable(timeOut);
long AfterTime = System.currentTimeMillis();
Long TimeDifference = AfterTime - BeforeTime;
time[i] = TimeDifference;
}