¿Cómo verificar la conexión a Internet para cada procesamiento en Android?
Frecuentes
Visto 339 veces
0
In my application, most of the processing in all Activity need to connect to Server to get data.
So, where should I check the Internet connection?
Is there any methods that can tell me when the connection is unavailable?
Finally, how to implement it? Is there any API for handle this case?
2 Respuestas
0
// just checks if network connectivity is available
public boolean isNetworkConnected(Context context){
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isAvailable() && cm.getActiveNetworkInfo().isConnected()) return true;
return false;
}//end method
Respondido 24 ago 12, 04:08
0
utilizar el ConnectivityManager
clase y Context.getSystemService(Context.CONNECTIVITY_SERVICE)
method.
More information: http://developer.android.com/reference/android/net/ConnectivityManager.html
Respondido 24 ago 12, 03:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android or haz tu propia pregunta.
duplicados stackoverflow.com/questions/4238921/… stackoverflow.com/questions/1560788/… stackoverflow.com/questions/4086159/… - januprasad
For the check the internet connection Go through this stackoverflow.com/a/12038094/1263679 - Rahul Patel