android – how to prevent webview to load when no internet connection
I have used the following in my projects: DetectConnection.Java import android.content.Context; import android.net.ConnectivityManager; public class DetectConnection { public static boolean checkInternetConnection(Context context) { ConnectivityManager con_manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); return (con_manager.getActiveNetworkInfo() != null && con_manager.getActiveNetworkInfo().isAvailable() && con_manager.getActiveNetworkInfo().isConnected()); } } Main code: if (!DetectConnection.checkInternetConnection(this)) { Toast.makeText(getApplicationContext(), “No Internet!”, Toast.LENGTH_SHORT).show(); } else { wv = (WebView) findViewById(R.id.donate_webView1); c … Read more