I'm trying to do a written report on some code and I found one on youtube. However I don't understand how this loop works. I understand that it must return a boolean value which then goes into another method but if someone could breakdown what is happening it would be greatly appreciated.
public class Loop {
public static boolean isConnectedToInternet(Context context){
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(context.CONNECTIVITY_SERVICE);
if (connectivityManager!=null){
NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
if (info!=null){
for (int i=0;i<info.length;i++){
if (info[i].getState() == NetworkInfo.State.CONNECTED)
return true;
}
}
}
return false;
}
}
Aucun commentaire:
Enregistrer un commentaire