Posts

Showing posts from September, 2015

Detect Internet Connection

Let's test a code in which you can detect if there is an active internet connectivity or not in your app programmatically. Create one class named Functions Create one method in that class as below: public static boolean isConnecting(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context. CONNECTIVITY_SERVICE ); NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo(); return activeNetworkInfo != null && activeNetworkInfo.isConnected(); } Now in your Activity, do this at where you want to check internet connection status: if (Functions.isConnecting(this)) { // you have internet connection // do your stuff here } else { Toast.makeText(this, "No internet connecion.", Toast.LENGTH_LONG).show(); }