how to test cell phone connectivity?
How to test network connection to tell if its a good signal or no signal? I would like to test this and do som开发者_JAVA技巧ething if the connectivity isn't good. I also would like to test for wifi connectivity.
This doesn't answer your question regarding whether it's a good connection or not, but this does figure out if it has a connection at all. Perhaps you can look at the objects in this method and see if it tells you more.
private boolean hasNetworkConnection() {
boolean HaveConnectedWifi = false;
boolean HaveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo)
{
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
HaveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
HaveConnectedMobile = true;
}
return HaveConnectedWifi || HaveConnectedMobile;
}
精彩评论