Android compruebe la conexión a Internet [duplicado]
Esta pregunta ya tiene una respuesta aquí:
¿Cómo verificar el acceso a internet en Android? InetAddress nunca agota el tiempo 49 respuestasQuiero crear una aplicación que use Internet y estoy tratando de crear una función que verifique si hay una conexión disponible y, si no lo está, vaya a una actividad que tenga un botón de reintento y una explicación.
Attached es mi código hasta ahora, pero recibo el errorSyntax error, insert "}" to complete MethodBody.
Ahora he estado colocando estos para intentar que funcione, pero hasta ahora no tuve suerte ... Cualquier ayuda sería apreciada.
public class TheEvoStikLeagueActivity extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 3000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
private boolean checkInternetConnection() {
ConnectivityManager conMgr = (ConnectivityManager) getSystemService (Context.CONNECTIVITY_SERVICE);
// ARE WE CONNECTED TO THE NET
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable() {
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(TheEvoStikLeagueActivity.this, IntroActivity.class);
TheEvoStikLeagueActivity.this.startActivity(mainIntent);
TheEvoStikLeagueActivity.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
} else {
return false;
Intent connectionIntent = new Intent(TheEvoStikLeagueActivity.this, HomeActivity.class);
TheEvoStikLeagueActivity.this.startActivity(connectionIntent);
TheEvoStikLeagueActivity.this.finish();
}
}
}