Saber se Internet está conectada

Top  Previous  Next

public boolean isInternetConnected() {

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();

        

        if (activeNetworkInfo != null){

            return true;

        }

        else{

            return false;

        }

    }