Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/05/2014, 17:49
volaveruntmissit
 
Fecha de Ingreso: octubre-2012
Mensajes: 45
Antigüedad: 11 años, 6 meses
Puntos: 0
Detectar conexion a internet y enviar a una activity

El asunto es, enviar a una activity si tiene conexion a internet, de lo contrario enviarlo a otra activity... Todo funciona muy bien pero he buscado mucho por Google y encuentro muchos ejemplos de como detectar si el dispositivo esta conectado a un WiFi o a los datos... Pero hasta ahora no encuentro uno que me funcione para saber si hay DATOS, osea si RECIBE.

De este modo detecto si está conectado a Internet:

Código:
public boolean isOnline() {
    ConnectivityManager cm = 
         (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo != null && netInfo.isConnected()) {
        return true;
    }
    return false;
}
De este modo recibo la informacion :


Código:
		
		if (!isOnline(this)) {
			  internet = false;
			} else {
				internet = true;
			  //Internet available. Do what's required when internet is available.
			}

Y así es como la proceso :

Código:
	        	if (internet == true) {
	          Intent mainIntent = new Intent().setClass(Inicio.this, Main.class);
	          startActivity(mainIntent);
	        	} else {
	  	          Intent mainIntent = new Intent().setClass(Inicio.this, NoInternet.class);
		          startActivity(mainIntent);
	        	}

De este modo hago que el usuario conectado a Internet reciba el Activity principal, y si no, recibe una Activity donde le hace saber un típico "Sin conexión"...

Funciona perfecto, pero solo detecta si hay conexion a internet, mas NO si TIENE INTERNET.

Me explico? Ojala que si...

Gracias por su ayuda.